我正在使用 Angular 11 和版本 10 的 augular-oauth-oidc
这是检查用户当前是否登录的正确方法吗?
@Injectable({
providedIn: 'root'
})
export class AuthService {
constructor(
private oauthService: OAuthService,
private router: Router,
) {
.
.
.
isLoggedIn(): boolean {
const identityClaim = this.oauthService.getIdentityClaims();
return identityClaim && identityClaim['name'] ? true : false;
}
我觉得这很hacky...我只是在检查名称字段是否存在于身份中?
这如何防止用户仅在其控制台中修改此变量 - 除了在 api 提交时进行服务器端检查或其他内容。
Angular 路由守卫和拦截器能完成这项工作吗?
谢谢!