title: Check Auth state from Firebase with Ngrx
body: <p>I am trying to check the authentication status of my application, verifying that it has an authenticated user.</p>
  
  <p>I have an initial state where <code>logged</code> is false, and when I try to check in <code>CanActivate()</code>, logged is being returned as false.</p>
  
  <p>I checked in <strong>Redux DevTools</strong> and the auth state is changed, so the logged value is changed to true.</p>
  
  <p>what am I doing wrong? How can I validate if the user is authenticated using NGRX?</p>
  
  <p><strong>guard.ts</strong></p>
  
  <pre><code> constructor(
      private _store: Store&lt;fromAuth.AuthState&gt;
    ) { }
  
   canActivate(): Observable&lt;boolean&gt; {
        return this.checkUserLogged(); // Return is always false 
   }
  
   private checkUserLogged() {
        return this._store.select(fromAuth.isLogged).pipe(take(1));
   }
  </code></pre>
  
  <p><strong>app.component.ts</strong></p>
  
  <pre><code>    import { Store } from '@ngrx/store';
      import * as fromAuth from '@myapp/store/reducers/auth.reducer';
      import * as authActions from '@myapp/store/actions/auth.actions';
  
       constructor(
           private _store: Store&lt;fromAuth.AuthState&gt;,
       ) {
  
      this._store.dispatch(new authActions.GetUser());
  </code></pre>
  
  <p><strong>auth.reducer.ts</strong></p>
  
  <pre><code> export interface AuthState {
       logged: boolean;
   ;
  
   export const initialState: AuthState = {
       logged: false,
   };
  
  
   export function authReducer(state = initialState, action: Action): 
      AuthState {
  
  switch (action.type) {
  
      case authActions.GET_USER:
          return {
              ...state,
              logged: false
          };
  
      case authActions.AUTHENTICATED:
          return {
              ...state,
              ...action.payload,
              loading: false,
              logged: true,
          };
  
        // emitted ....
  
   }
  
   export const getAuthState = createFeatureSelector&lt;AuthState&gt;('auth');
  
   export const isLogged = createSelector(
       getAuthState, (state: AuthState) =&gt; 
       state.logged);
  </code></pre>
  
  <p><strong>auth.effects.ts</strong></p>
  
  <pre><code>@Injectable({
      providedIn: 'root'
  })
  
  export class AuthEffects {
  
  constructor(
      private _actions: Actions,
      private _angularFireAuth: AngularFireAuth) { }
  
  @Effect()
  getUser$: Observable&lt;Action&gt; = this._actions.pipe(
      ofType(authActions.GET_USER),
      switchMap(() =&gt; this._angularFireAuth.authState),
      switchMap(user =&gt; forkJoin([
          from(user.getIdTokenResult(true)), of(user)])
          .pipe(map(([token, user]) =&gt; {
  
              if (user) {
                  const authState = {
                      firestoreCollection: token.claims.firestoreCollection,
                      user: {
                          admin: token.claims.admin,
                          uid: user.uid,
                          displayName: user.displayName
                      }
                  };
  
                  // You are returning this action
                  // Soon after logged in should be true.
                  return new authActions.Authenticated(authState);
  
              } else {
                  return new authActions.NotAuthenticated();
              }
          }))),
      catchError((error) =&gt; of(new authActions.AuthError(error)))
  )
  </code></pre>
  
  <p>}</p>