src/app/auth/helpers/auth.guard.ts
Methods |
constructor(router: Router, authService: AuthService)
|
|||||||||
|
Defined in src/app/auth/helpers/auth.guard.ts:10
|
|||||||||
|
Parameters :
|
| canActivate | |||||||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot)
|
|||||||||
|
Defined in src/app/auth/helpers/auth.guard.ts:14
|
|||||||||
|
Parameters :
Returns :
Observable | Promise | boolean | UrlTree
|
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, Router } from '@angular/router';
import { Observable } from 'rxjs';
import {AuthService} from '@app/auth/services/auth.service';
@Injectable({
providedIn: 'root'
})
export class AuthGuard implements CanActivate {
constructor(private router: Router, private authService: AuthService) {}
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
const currentUser = this.authService.currentUserValue;
if (currentUser) {
return true;
}
this.router.navigate(['login'], { queryParams: { returnUrl: state.url } });
return false;
}
}