我没有登录页面,这是 sso 调用
在应用程序组件中,我已经调度了一个动作来加载服务器端令牌调用并获取令牌,并且基于用户角色我可以激活路由中的守卫。如果警卫激活返回 true,我将进入仪表板页面。
在dashboard页面中,我在浏览器URL中进行了刷新,可以在登录动作效果之前激活execute,因此可以激活return false,页面显示空白。
在dashboard有子路由,也有productsdashboard/products等子链接,也有激活的guard,但是可以在login dispatch action影响成功调用之前激活return false。
谁能帮助我我做错了什么?
这里是路由,
{
path: '',
component: HomeComponent,
canActivate:[AuthGuard],
children: [
{
path: 'product',
loadChildren: () => productModule
},
{
path: 'order',
loadChildren: () => orderModule
}
]
},
这是激活方法:在这里我从效果调用中获得成功,同时从 app.component 调度一个动作:
canActivate(): Observable<boolean> {
return this.store.select(appState => appState.auth.isAuthenticated)
.pipe(map(authUser => {
if (!authUser) {
return authUser;
}
return authUser;
}))
}
应用程序组件:
ngOnInit(){
this.onSubmit();
}
onSubmit(): void {
const payload = {
email: 'test@test.com',
password: 'admin'
};
alert('dispatch an action');
this.store.dispatch(new LogIn(payload));
}
问题只在页面刷新。单击路由器链接时,逻辑工作正常。
我的初始状态:
export const initialState: State = {
isAuthenticating:false,
isAuthenticated: false,
user: null,
errorMessage: null
};