Files
edr-platform/apps/edr-passenger-web/backoffice/src/lib/use-permission.ts

28 lines
862 B
TypeScript

'use client';
import { useAuthStore } from './auth-store';
/**
* Returns whether the current user has a given permission key.
* Super admins and org admins always return true.
*
* Usage:
* const canCancel = usePermission(PERMS.bookings.cancel);
* {canCancel && <button>Cancel Booking</button>}
*/
export function usePermission(key: string): boolean {
return useAuthStore((s) => s.hasPermission(key));
}
/**
* Same as usePermission but WITHOUT the super-admin / org-admin bypass — the
* permission must be explicitly granted. Use it wherever the API endpoint is
* guarded with PassengerStaffStrict, so the UI matches what the API allows.
*
* Usage:
* const canIssue = usePermissionStrict(PERMS.tickets.generate);
*/
export function usePermissionStrict(key: string): boolean {
return useAuthStore((s) => s.hasPermissionStrict(key));
}