Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
auth-guard.service.ts from version 7.3.0 of ngrx/platform
// 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