Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
32 lines (26 sloc) 893 Bytes
import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree} from '@angular/router';
import {Observable} from 'rxjs';
import {AuthService} from './auth.service';
import {map} from 'rxjs/operators';
providedIn: 'root'
export class AuthGuard implements CanActivate {
constructor(private readonly authService: AuthService,
private readonly router: Router) {
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):
Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
if (this.authService.isLoggedIn()) {
return true;
return this.authService.isAuthenticated().pipe(map(authenticated => {
if (authenticated) {
return true;
return this.router.parseUrl('/login');
You can’t perform that action at this time.