UNPKG

@better-auth-ui/core

Version:

Authentication components and data utilities for [Better Auth](https://better-auth.com), available for React and Solid.

40 lines (39 loc) 1.83 kB
/** * Better Auth stores a member's or invitation's roles as one comma-joined * string, so `"admin,member"` is a single value rather than two. Anything that * compares, filters, or renders a role has to split it first. */ export declare function parseMemberRoles(role: string | null | undefined): string[]; /** * Join roles back into the comma-joined form Better Auth persists. Endpoints * accept an array too, so this is only needed for optimistic local state. */ export declare function formatMemberRoles(roles: readonly string[]): string; /** * Whether a member holds a role, regardless of any others they hold. * * Use this instead of `member.role === "owner"`, which silently misses an * owner who also carries a second role. */ export declare function hasMemberRole(role: string | null | undefined, candidate: string): boolean; /** * Resolve each of a member's roles to its configured label, falling back to * the raw role name for roles the UI has no label for. * * @param role - The raw comma-joined role value. * @param labels - The `roles` label map from the organization plugin. */ export declare function memberRoleLabels(role: string | null | undefined, labels: Record<string, string> | undefined): string[]; export type DynamicOrganizationRole = { id: string; role: string; permission: Record<string, string[]>; }; /** Merge configured labels with roles stored by Better Auth. */ export declare function mergeOrganizationRoleLabels(labels: Record<string, string> | undefined, dynamicRoles: readonly Pick<DynamicOrganizationRole, "role">[] | null | undefined): { [x: string]: string; }; /** Return members that currently hold the supplied role. */ export declare function membersWithRole<T extends { role?: string | null; }>(members: readonly T[] | undefined, role: string): T[];