From 9b925712cbdedacdf8af947e929ca3975b56e3fa Mon Sep 17 00:00:00 2001 From: Danijel Andjelkovic Date: Sat, 5 Mar 2022 19:46:16 +0100 Subject: Added auth and auth guard services, included ngx-cookie-service and angular-jwt. Made a configuration file. --- frontend/src/app/auth-guard.service.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 frontend/src/app/auth-guard.service.ts (limited to 'frontend/src/app/auth-guard.service.ts') 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 | Promise { + if (this.auth.isAuthenticated()) { + return true; + } + this.router.navigate(['login']); + return false; + } +} -- cgit v1.2.3