Skip to content

Instantly share code, notes, and snippets.

@gdyrrahitis
Created August 18, 2018 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gdyrrahitis/1810267b4f3cc5e56df1392d25a4f3a3 to your computer and use it in GitHub Desktop.
Save gdyrrahitis/1810267b4f3cc5e56df1392d25a4f3a3 to your computer and use it in GitHub Desktop.
export class AuthGuard implements CanActivate {
constructor(private authService: AuthService, private router: Router) {
}
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
if(this.authService.isAuthenticated()) {
return true;
}
this.router.navigate(['/login'], { queryParams: { returnUrl: state.url } });
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment