]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/services/auth-guard.service.ts
update ceph source to reef 18.2.0
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / services / auth-guard.service.ts
1 import { Injectable } from '@angular/core';
2 import {
3 ActivatedRouteSnapshot,
4 CanActivate,
5 CanActivateChild,
6 Router,
7 RouterStateSnapshot
8 } from '@angular/router';
9
10 import { AuthStorageService } from './auth-storage.service';
11
12 @Injectable({
13 providedIn: 'root'
14 })
15 export class AuthGuardService implements CanActivate, CanActivateChild {
16 constructor(private router: Router, private authStorageService: AuthStorageService) {}
17
18 canActivate(_route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
19 if (this.authStorageService.isLoggedIn()) {
20 return true;
21 }
22 this.router.navigate(['/login'], { queryParams: { returnUrl: state.url } });
23 return false;
24 }
25
26 canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
27 return this.canActivate(childRoute, state);
28 }
29 }