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 { ...@@ -8,5 +8,7 @@ export class AdminGuard implements CanActivate {
constructor() {} constructor() {}
canActivate(): boolean { canActivate(): boolean {
return true; return true;
// return false if user role is not admin
// return false;
} }
} }
...@@ -3,7 +3,8 @@ export namespace Login { ...@@ -3,7 +3,8 @@ export namespace Login {
user: { user: {
username: string, username: string,
role: string, role: string,
} },
accessToken: string,
}; };
export type Request = { export type Request = {
......
...@@ -9,8 +9,8 @@ import { Observable, map } from "rxjs"; ...@@ -9,8 +9,8 @@ import { Observable, map } from "rxjs";
}) })
export class AuthService { export class AuthService {
constructor( constructor(
private _http: HttpClient private _http: HttpClient,
) { } ) {}
loginPost(request: Login.Request) { loginPost(request: Login.Request) {
return this._http return this._http
......
...@@ -70,7 +70,8 @@ export class LoginComponent implements OnInit { ...@@ -70,7 +70,8 @@ export class LoginComponent implements OnInit {
} }
onSuccess(response: ResponseResult<Login.Response>) { 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']); 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