mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 21:35:50 +00:00
26 lines
672 B
TypeScript
26 lines
672 B
TypeScript
|
|
import { Injectable } from '@angular/core';
|
||
|
|
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, Router } from '@angular/router';
|
||
|
|
import { Observable } from 'rxjs';
|
||
|
|
|
||
|
|
@Injectable({
|
||
|
|
providedIn: 'root'
|
||
|
|
})
|
||
|
|
export class AuthGuard implements CanActivate {
|
||
|
|
constructor(
|
||
|
|
private router:Router
|
||
|
|
){}
|
||
|
|
|
||
|
|
canActivate(
|
||
|
|
route: ActivatedRouteSnapshot,
|
||
|
|
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
||
|
|
|
||
|
|
if(window.location.pathname != '' && !localStorage.getItem('UserData')) {
|
||
|
|
this.router.navigate(['/']);
|
||
|
|
return false
|
||
|
|
} else {
|
||
|
|
return true
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|