src/app/user/auth-guard.service.ts
Methods |
constructor(authService: AuthService, router: Router)
|
|||||||||
Defined in src/app/user/auth-guard.service.ts:10
|
|||||||||
Parameters :
|
canActivate | |||||||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot)
|
|||||||||
Defined in src/app/user/auth-guard.service.ts:16
|
|||||||||
Parameters :
Returns :
boolean
|
checkLoggedIn | ||||||
checkLoggedIn(url: string)
|
||||||
Defined in src/app/user/auth-guard.service.ts:20
|
||||||
Parameters :
Returns :
boolean
|
import { CanActivate } from '@angular/router';
import { Injectable } from '@angular/core';
import { AuthService } from 'src/app/user/auth.service';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Router } from '@angular/router';
@Injectable({
providedIn:'root'
})
export class AuthGuard implements CanActivate{
constructor(private authService: AuthService,
private router: Router){
}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean{
return this.checkLoggedIn(state.url);
}
checkLoggedIn(url: string): boolean{
if( this.authService.isLoggedIn())
return true;
// Retain the attempted URL for redirection
this.authService.redirectUrl = url;
this.router.navigate(['kycform/login']);
return false;
}
}