import { Autocomplete } from "./utils.mjs"; import { CheckAuthorizationWithCustomPermissions, PendingSessionOptions } from "./session.mjs"; import { OrganizationCustomPermissionKey, OrganizationCustomRoleKey } from "./organizationMembership.mjs"; //#region src/types/authorization.d.ts type RoleProtectParams = { condition?: never; feature?: never; permission?: never; plan?: never; role: OrganizationCustomRoleKey; }; type PermissionProtectParams = { condition?: never; feature?: never; permission: OrganizationCustomPermissionKey; plan?: never; role?: never; }; type ConditionProtectParams = { condition: (has: CheckAuthorizationWithCustomPermissions) => boolean; feature?: never; permission?: never; plan?: never; role?: never; }; type FeatureProtectParams = { condition?: never; feature: Autocomplete<`user:${string}` | `org:${string}`>; permission?: never; plan?: never; role?: never; }; type PlanProtectParams = { condition?: never; feature?: never; permission?: never; plan: Autocomplete<`user:${string}` | `org:${string}`>; role?: never; }; /** * Authorization parameters used by `auth.protect()`. * * Use `ProtectParams` to specify the required role, permission, feature, or plan for access. */ type ProtectParams = ConditionProtectParams | FeatureProtectParams | PermissionProtectParams | PlanProtectParams | RoleProtectParams; /** * Authorization parameters for `` component. * Excludes `condition` since `Show` expects functions to be passed directly to `when`. */ type ShowProtectParams = FeatureProtectParams | PermissionProtectParams | PlanProtectParams | RoleProtectParams; /** * Authorization condition for the `when` prop in ``. * Can be an object specifying role, permission, feature, or plan, * or a callback function receiving the `has` helper for complex conditions. * * Note: Unlike `ProtectParams`, this excludes the `condition` variant since * `` expects functions to be passed directly to `when`, not wrapped * in `{ condition: fn }`. */ type ShowWhenCondition = 'signed-in' | 'signed-out' | ShowProtectParams | ((has: CheckAuthorizationWithCustomPermissions) => boolean); /** * Props for the `` component, which conditionally renders children based on authorization. * * @example * ```tsx * // Require a specific permission * ... * * // Require a specific role * ... * * // Use a custom condition callback * has({ permission: "org:read" }) && someCondition}>... * * // Require a specific feature * ... * * // Require a specific plan * ... * ``` */ type ShowProps = PendingSessionOptions & { fallback?: unknown; when: ShowWhenCondition; }; //#endregion export { ProtectParams, ShowProps, ShowWhenCondition }; //# sourceMappingURL=authorization.d.mts.map