- added organizations - added industries - added logo in 2 colors for light and dark theme - improved authorization to allow multi tenancy
20 lines
679 B
TypeScript
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));
|
|
}
|
|
}
|