Skip to content

Instantly share code, notes, and snippets.

@nhh
Last active May 28, 2018 14:24
Show Gist options
  • Save nhh/d2abcdcf59b32c2b337c080e26f8b472 to your computer and use it in GitHub Desktop.
Save nhh/d2abcdcf59b32c2b337c080e26f8b472 to your computer and use it in GitHub Desktop.
IsAuthenticatedGuard
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanActivateChild} from '@angular/router';
import { Router} from "@angular/router";
import { Observable } from 'rxjs';
import { AuthService } from '../service/auth/auth.service';
@Injectable({
providedIn: 'root'
})
export class IsAuthenticatedGuard implements CanActivate {
constructor(
private authService: AuthService
) {};
canActivate(
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