fix(web): centralizar acceso a administración avanzada
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
import type { AuthUser } from '../lib/api';
|
||||||
|
|
||||||
|
function normalizeRole(value: string) {
|
||||||
|
return value
|
||||||
|
.normalize('NFD')
|
||||||
|
.replace(/[\u0300-\u036f]/g, '')
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(/[^a-z0-9]+/g, ' ')
|
||||||
|
.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
const ADMIN_ROLES = new Set([
|
||||||
|
'admin',
|
||||||
|
'administrator',
|
||||||
|
'administrador',
|
||||||
|
'superadmin',
|
||||||
|
'super admin',
|
||||||
|
'superadministrator',
|
||||||
|
'super administrator',
|
||||||
|
'superadministrador',
|
||||||
|
'super administrador',
|
||||||
|
]);
|
||||||
|
|
||||||
|
export function hasAdministratorRole(user: AuthUser | null) {
|
||||||
|
return Boolean(user?.roles.some((role) => ADMIN_ROLES.has(normalizeRole(role))));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user