diff options
author | Danijel Andjelkovic <adanijel99@gmail.com> | 2022-03-05 19:46:16 +0100 |
---|---|---|
committer | Danijel Andjelkovic <adanijel99@gmail.com> | 2022-03-05 19:46:16 +0100 |
commit | 9b925712cbdedacdf8af947e929ca3975b56e3fa (patch) | |
tree | 5a1c230a2c9484dd610df74b09c861fb20b2d853 /frontend/src/app/auth-guard.service.ts | |
parent | cfadf0c8edfc66e54df8186d98b968c5682a3356 (diff) |
Added auth and auth guard services, included ngx-cookie-service and angular-jwt. Made a configuration file.
Diffstat (limited to 'frontend/src/app/auth-guard.service.ts')
-rw-r--r-- | frontend/src/app/auth-guard.service.ts | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/frontend/src/app/auth-guard.service.ts b/frontend/src/app/auth-guard.service.ts new file mode 100644 index 00000000..b6d3678d --- /dev/null +++ b/frontend/src/app/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; + } +} |