[英]Angular AuthGuard with NGRX
I am trying to use the AuthGuard with NGRX, but i always get undefined on this route:我正在尝试将 AuthGuard 与 NGRX 一起使用,但我总是在这条路线上未定义:
When i look at Store, the estaAutenticado is true, but i cant get on time, because its async?当我查看 Store 时,estaAutenticado 是正确的,但我无法准时到达,因为它是异步的?
My guard:我的守卫:
return this.store.pipe(
select(fromAuth.getEstaAutenticado ),
map(authed => {
console.log(authed) // <---- Always return undefined
if (!authed) {
this.router.navigate(['/'])
return false;
}
return true;
})
);
}
```
// Reducer
export interface State {
usuario: Usuario,
estaAutenticado: boolean,
erro: string
}
export const initialState: State = {
usuario: null,
estaAutenticado: false,
erro: ''
};
export const getUsuario = (state: State) => state.usuario;
export const getEstaAutenticado = (state: State) => state.estaAutenticado;
export const getErro = (state: State) => state.erro;
解决了,我错过了 selectorFeature
export const selecionaState = createFeatureSelector<State>('autenticacao');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.