import { Injectable } from '@angular/core'
import { CanActivate } from '@angular/router'
import { JwtHelperService } from '@auth0/angular-jwt'
import { Store } from '@ngrx/store'
import { Observable } from 'rxjs/Observable'
import { of } from 'rxjs/observable/of'
import { map, take, tap } from 'rxjs/operators'

import * as AuthActions from '../store/auth.actions'
import * as fromAuth from '../store/auth.reducer'

@Injectable()
export class AuthGuard implements CanActivate {
  constructor(
    private store: Store<fromAuth.State>,
    public jwtHelper: JwtHelperService
  ) {}

  canActivate(): Observable<boolean> {
    return this.store.select(fromAuth.getIsLoggedIn).pipe(
      map(isLoggedIn => {
        if (this.jwtHelper.isTokenExpired()) {
          this.store.dispatch(new AuthActions.LoginRedirect())
          return false
        }

        if (!isLoggedIn) {
          this.store.dispatch(new AuthActions.RehydrateAuth())
        }

        return true
      }),
      take(1)
    )
  }
}

import { Injectable } from '@angular/core'
import { CanActivate } from '@angular/router'
import { Store } from '@ngrx/store'
import { Observable } from 'rxjs/Observable'
import { of } from 'rxjs/observable/of'
import { map, take, tap } from 'rxjs/operators'

import * as AuthActions from '../store/auth.actions'
import * as fromAuth from '../store/auth.reducer'

@Injectable()
export class AuthGuard implements CanActivate {
  constructor(private store: Store<fromAuth.State>) {}

  canActivate(): Observable<boolean> {
    return this.store.select(fromAuth.getIsLoggedIn).pipe(
      map(isLoggedIn => {
        if (!isLoggedIn) {
          this.store.dispatch(new AuthActions.LoginRedirect())
          return false
        }

        return true
      }),
      take(1)
    )
  }
}

--- 
+++ 
@@ -1,5 +1,6 @@
 import { Injectable } from '@angular/core'
 import { CanActivate } from '@angular/router'
+import { JwtHelperService } from '@auth0/angular-jwt'
 import { Store } from '@ngrx/store'
 import { Observable } from 'rxjs/Observable'
 import { of } from 'rxjs/observable/of'
@@ -10,14 +11,21 @@
 
 @Injectable()
 export class AuthGuard implements CanActivate {
-  constructor(private store: Store<fromAuth.State>) {}
+  constructor(
+    private store: Store<fromAuth.State>,
+    public jwtHelper: JwtHelperService
+  ) {}
 
   canActivate(): Observable<boolean> {
     return this.store.select(fromAuth.getIsLoggedIn).pipe(
       map(isLoggedIn => {
-        if (!isLoggedIn) {
+        if (this.jwtHelper.isTokenExpired()) {
           this.store.dispatch(new AuthActions.LoginRedirect())
           return false
+        }
+
+        if (!isLoggedIn) {
+          this.store.dispatch(new AuthActions.RehydrateAuth())
         }
 
         return true
Check token expiration and rehydrate auth store
