我正在使用 Angular,这是用于我的身份验证检查:
export class EnsureAuthenticated implements CanActivate {
constructor(private auth: AuthService, private router: Router) {}
canActivate(): boolean {
if (localStorage.getItem('token')) {
return true;
}
else {
this.router.navigateByUrl('/login');
return false;
}
}
}
{
path: 'path',
component: myComponent,
canActivate: [EnsureAuthenticated]
}
Run Code Online (Sandbox Code Playgroud)
它工作正常,但我的问题是用户和管理员都可以访问此页面。
我知道我没有设置任何条件。如何在其上设置适当的条件?
我不想让管理员访问此页面