Created
March 7, 2019 22:49
-
-
Save jtcrowson/5653c6cb9fb64cc52066e81dc818742d to your computer and use it in GitHub Desktop.
auth-guard.service.ts from version 7.3.0 of ngrx/platform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NgRx v7.3.0 | |
@Injectable({ | |
providedIn: 'root', | |
}) | |
export class AuthGuard implements CanActivate { | |
constructor(private store: Store<fromAuth.State>) {} | |
canActivate(): Observable<boolean> { | |
return this.store.pipe( | |
select(fromAuth.getLoggedIn), | |
map(authed => { | |
if (!authed) { | |
this.store.dispatch(new AuthApiActions.LoginRedirect()); | |
return false; | |
} | |
return true; | |
}), | |
take(1) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment