Files
ipal-kit/dist/modules/access/predicates.d.ts
T
2026-07-31 23:21:51 +02:00

21 lines
862 B
TypeScript

import type { Role } from './types.js';
/**
* The plugin can't know the client's generated User type, and Payload types
* `req.user` loosely (UntypedUser | null). Predicates therefore accept an
* unknown-ish user and read `roles` defensively — no assumptions about shape
* beyond an optional roles array.
*/
type MaybeUser = {
roles?: null | Role[];
} | null | Record<string, unknown> | undefined;
/**
* True if the user holds at least the given role in the hierarchy.
* admin satisfies 'editor' and 'user'; editor satisfies 'user'.
*/
export declare function hasMinimumRole(user: MaybeUser, minimum: Role): boolean;
/** True if the user is an admin. */
export declare function isAdmin(user: MaybeUser): boolean;
/** True if the user is an editor or higher (editor, admin). */
export declare function isEditor(user: MaybeUser): boolean;
export {};