Files
enerport-web-app/src/app/pipes/is-role-allowed-pipe.ts
Murat Özkorkmaz e901aefbf5 Several fixes
- added organizations
- added industries
- added logo in 2 colors for light and dark theme
- improved authorization to allow multi tenancy
2025-11-13 19:56:50 +01:00

20 lines
679 B
TypeScript

import { Pipe, PipeTransform } from '@angular/core';
import Keycloak from 'keycloak-js';
@Pipe({
name: 'isRoleAllowed',
standalone: true
})
export class IsRoleAllowedPipe implements PipeTransform {
constructor(private keycloak: Keycloak) {}
transform(allowed: string | string[], mode: 'any' | 'all' = 'any'): boolean {
const userRoles = this.keycloak.realmAccess?.roles ?? [];
const allowedRoles = Array.isArray(allowed) ? allowed : [allowed];
if (!allowedRoles.length) return true;
if (mode === 'all') return allowedRoles.every(r => userRoles.includes(r));
return allowedRoles.some(r => userRoles.includes(r));
}
}