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