Commit a0c87f85 authored by vtduong0912's avatar vtduong0912

update: store token & role into localStorage

parent e2113669
......@@ -8,5 +8,7 @@ export class AdminGuard implements CanActivate {
constructor() {}
canActivate(): boolean {
return true;
// return false if user role is not admin
// return false;
}
}
......@@ -3,7 +3,8 @@ export namespace Login {
user: {
username: string,
role: string,
}
},
accessToken: string,
};
export type Request = {
......
......@@ -9,8 +9,8 @@ import { Observable, map } from "rxjs";
})
export class AuthService {
constructor(
private _http: HttpClient
) { }
private _http: HttpClient,
) {}
loginPost(request: Login.Request) {
return this._http
......
......@@ -70,7 +70,8 @@ export class LoginComponent implements OnInit {
}
onSuccess(response: ResponseResult<Login.Response>) {
console.log(response);
localStorage.setItem("token", JSON.stringify(response.responseData?.accessToken) ?? "");
localStorage.setItem("role", JSON.stringify(response.responseData?.user.role) ?? "");
this._router.navigate(['/home']);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment