diff options
author | Danijel Andjelkovic <adanijel99@gmail.com> | 2022-03-07 19:15:03 +0100 |
---|---|---|
committer | Danijel Andjelkovic <adanijel99@gmail.com> | 2022-03-07 19:15:03 +0100 |
commit | 9eb7f0dd8c22782fed9ccf96fbfec3cedff2b892 (patch) | |
tree | 410d87cfa28f1497819fe99b2f54180d364d6857 /frontend/src/app/_services/auth-guard.service.ts | |
parent | 5fdb50247c66811964fb20801f0abc2a7c585303 (diff) | |
parent | c59ff03b96d7b638623c254dfe8477055aeb2a35 (diff) |
Merge branch 'frontend' of http://gitlab.pmf.kg.ac.rs/igrannonica/neuronstellar into dev
Diffstat (limited to 'frontend/src/app/_services/auth-guard.service.ts')
-rw-r--r-- | frontend/src/app/_services/auth-guard.service.ts | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/frontend/src/app/_services/auth-guard.service.ts b/frontend/src/app/_services/auth-guard.service.ts new file mode 100644 index 00000000..b6d3678d --- /dev/null +++ b/frontend/src/app/_services/auth-guard.service.ts @@ -0,0 +1,21 @@ +import { Injectable } from '@angular/core'; +import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router'; +import { Observable } from 'rxjs'; +import { AuthService } from './auth.service'; + + +@Injectable({ + providedIn: 'root' +}) +export class AuthGuardService implements CanActivate { + + constructor(private auth: AuthService, private router: Router) { } + + canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean | UrlTree | Observable<boolean | UrlTree> | Promise<boolean | UrlTree> { + if (this.auth.isAuthenticated()) { + return true; + } + this.router.navigate(['login']); + return false; + } +} |