我正在使用带有 Angular Material 的弹出登录,当我添加 Angular Universal 时,身份验证防护就是问题所在。如果某些路由受到身份验证保护,则页面只会开始挂起,并且永远不会结束。没有 Angular Universal 的行为是重新加载页面时它只是打开弹出窗口进行登录。
@Injectable()
export class AuthGuard implements CanActivate {
constructor(readonly auth: AuthService, public router: Router, private dialog: MatDialog, private store: Store<fromAuth.State>) {}
/** Performs the user authentication prompting the user when neeed or resolving to the current authenticated user otherwise */
public authenticate(action: loginAction = 'signIn') {
return this.store.pipe(
select(fromAuth.selectAuthState),
take(1),
switchMap(user => !user.user ? this.prompt(action) : of(user.user))
).toPromise();
}
public prompt(data: loginAction = 'signIn'): Promise<any> {
return this.dialog.open<LogInComponent, loginAction>(LogInComponent, { data …Run Code Online (Sandbox Code Playgroud)