cic-staff-client/src/app/_guards/auth.guard.ts
2020-12-28 12:05:33 +03:00

24 lines
663 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 (localStorage.getItem(atob('CICADA_USER'))) {
return true;
}
this.router.navigate(['/auth'], { queryParams: { returnUrl: state.url }});
return false;
}
}