Angular AuthGuard с NGRX - PullRequest
       5

Angular AuthGuard с NGRX

0 голосов
/ 09 марта 2020

Я пытаюсь использовать AuthGuard с NGRX, но я всегда получаю неопределенность на этом маршруте:

Когда я смотрю на Store, estaAutenticado - это правда, но я не могу успеть вовремя, потому что это асин c?

Моя стража:

     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;

1 Ответ

0 голосов
/ 11 марта 2020

Решено, мне не хватало селектораFeature

export const selecionaState = createFeatureSelector<State>('autenticacao');
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...