projects/isy-angular-widgets/src/lib/security/security-guard.ts
An AuthGuard that can check whether certain routes can be loaded or activated with current permissions. Can e.g. be used in app-routing-module:
{ path: 'personen', canLoad: [AuthGuard] }
Methods |
| canActivate | ||||||||
canActivate(route: ActivatedRouteSnapshot)
|
||||||||
|
Determines if a given route can be accessed
Parameters :
Returns :
Observable<boolean>
An observable that eventually outputs a boolean whether the given route can be accessed |
import {inject, Injectable} from '@angular/core';
import {ActivatedRouteSnapshot} from '@angular/router';
import {Observable} from 'rxjs';
import {SecurityService} from './security-service';
/**
* An AuthGuard that can check whether certain routes can be loaded or activated with current permissions.
* Can e.g. be used in app-routing-module:
*
*
* {
* path: 'personen',
* canLoad: [AuthGuard]
* }
*/
@Injectable({providedIn: 'root'})
export class AuthGuard {
/**
* A service that can be configured with permission configuration and return permissions for certain elements.
*/
private readonly securityService = inject(SecurityService);
/**
* Determines if a given route can be accessed
* @param route The route to check
* @returns An observable that eventually outputs a boolean whether the given route can be accessed
*/
canActivate(route: ActivatedRouteSnapshot): Observable<boolean> {
return this.securityService.checkRoutePermission(route);
}
}