I am trying to use the AuthGuard with NGRX, but i always get undefined on this route:
When i look at Store, the estaAutenticado is true, but i cant get on time, because its async?
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;
Solved, I was missing the selectorFeature
export const selecionaState = createFeatureSelector<State>('autenticacao');