You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

31 lines
703 B

// TODO: implement ABAC
export const actions = {
ADMIN: 'ADMIN',
CLIENT: 'CLIENT',
} as const;
export type Role = number & { readonly __role: unique symbol };
export const roles = {
ADMIN: 1 as Role,
CLIENT: 2 as Role,
} as const;
export type Action = keyof typeof actions;
type MATRIX = {
readonly [key in keyof typeof actions]: readonly (typeof roles)[keyof typeof roles][];
};
export const MATRIX: MATRIX = {
[actions.ADMIN]: [roles.ADMIN] as const,
[actions.CLIENT]: [roles.CLIENT, roles.ADMIN] as const,
} as const;
export const checkPermissions = (action: Action, user: { role: Role }) => {
if (!MATRIX[action].includes(user.role)) {
return false;
}
return true;
};