import { KeycloakRolesConfig } from '../roles/keycloak-config.js'; /** * React hook for type-safe realm role checking. * * This hook provides a type-safe way to check if the authenticated user has * specific realm roles. It returns an object with `hasRealmRole` function that * provides autocomplete for the specified role names. * * @template T - Readonly array of role name strings * @param roles - Array of realm role names to check * @returns Object with `hasRealmRole` function for type-safe role checking * * @example Basic usage * ```tsx * import { useRealmRoles } from 'keycloak-headless/react'; * * function AdminPanel() { * const { hasRealmRole } = useRealmRoles(['admin', 'moderator'] as const); * * if (!hasRealmRole('admin')) { * return
Access denied
; * } * * return
Admin Panel
; * } * ``` * * @example Multiple role checks * ```tsx * function Dashboard() { * const { hasRealmRole } = useRealmRoles(['admin', 'editor', 'viewer'] as const); * * return ( *
* {hasRealmRole('admin') && } * {hasRealmRole('editor') && } * {hasRealmRole('viewer') && } *
* ); * } * ``` * * @example Conditional rendering * ```tsx * function UserList() { * const { hasRealmRole } = useRealmRoles(['user-manager'] as const); * * return ( *
*

Users

* {hasRealmRole('user-manager') ? ( * * ) : ( *

View only

* )} *
* ); * } * ``` */ export declare function useRealmRoles(roles: T): { hasRealmRole(role: T[number]): boolean; roles: T; }; /** * React hook for type-safe role checking using generated Keycloak config. * * This hook works with the Vite plugin-generated configuration to provide * fully type-safe role checking with autocomplete for both realm and client roles. * The config is typically imported from the generated file. * * @template C - KeycloakRolesConfig type * @param config - Generated Keycloak roles configuration object * @returns Object with `hasRealmRole` and `hasClientRole` functions * * @example With generated config * ```tsx * import { useKeycloakConfigRoles } from 'keycloak-headless/react'; * import { KEYCLOAK_CONFIG } from './keycloak-config.generated'; * * function ProtectedFeature() { * const { hasRealmRole, hasClientRole } = useKeycloakConfigRoles(KEYCLOAK_CONFIG); * * // Type-safe role checking with autocomplete * if (!hasRealmRole('premium-user')) { * return ; * } * * return ; * } * ``` * * @example Client roles * ```tsx * function ClientSpecificFeature() { * const { hasClientRole } = useKeycloakConfigRoles(KEYCLOAK_CONFIG); * * // Check client-specific roles * if (hasClientRole('my-client', 'manage-users')) { * return ; * } * * return
Access denied
; * } * ``` * * @example Multiple role checks * ```tsx * function Dashboard() { * const { hasRealmRole, hasClientRole } = useKeycloakConfigRoles(KEYCLOAK_CONFIG); * * const isAdmin = hasRealmRole('admin'); * const canManageUsers = hasClientRole('my-app', 'manage-users'); * const canViewReports = hasClientRole('my-app', 'view-reports'); * * return ( *
* {isAdmin && } * {canManageUsers && } * {canViewReports && } *
* ); * } * ``` * * @example Role-based navigation * ```tsx * function Navigation() { * const { hasRealmRole } = useKeycloakConfigRoles(KEYCLOAK_CONFIG); * * return ( * * ); * } * ``` */ export declare function useKeycloakConfigRoles(config: C): { config: C; hasRealmRole(role: C["roles"] extends readonly (infer R extends string)[] ? R : never): boolean; hasClientRole(clientId: Id, role: (C["clientRoles"] & {})[Id] extends readonly (infer R extends string)[] ? R : never): boolean; clientRoleChecker(clientId: Id): { hasClientRole(role: string): boolean; clientId: Id; roles: readonly string[]; }; }; //# sourceMappingURL=use-realm-roles.d.ts.map