Last active
May 29, 2018 09:37
-
-
Save nhh/ae3acb04cda5c9f29277dd7a57880c46 to your computer and use it in GitHub Desktop.
Authenticated Guard for nested views. (child views)
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
import { Injectable } from '@angular/core'; | |
import {CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanActivateChild} from '@angular/router'; | |
import {Observable} from 'rxjs'; | |
import {AuthService} from '../service/auth/auth.service'; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class IsAuthenticatedGuard implements CanActivate, CanActivateChild { | |
constructor( | |
private authService: AuthService | |
) {}; | |
canActivate( | |
next: ActivatedRouteSnapshot, | |
state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean { | |
return this.authService.isAuthenticated(); | |
} | |
canActivateChild( | |
next: ActivatedRouteSnapshot, | |
state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean { | |
return this.authService.isAuthenticated(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment