BETTER-AUTH. UI
API Reference

AuthHooks

Comprehensive reference for authentication-related hooks used by better-auth-ui.

The AuthHooks type defines the set of authentication-related hooks used by the UI provider and components. These hooks are typically provided by the better-auth client and passed to the <AuthUIProvider />.

Reference

PropTypeDefault
useIsRestoring?
(() => boolean)
-
useListMembers
(params: any) => AuthHook<{ members: any[]; total: number; }>
-
useListUserInvitations
() => AuthHook<Invitation[]>
-
useListInvitations
(params: any) => AuthHook<Invitation[]>
-
useInvitation
(params: any) => AuthHook<Invitation & { organizationName: string; organizationSlug: string; organizationLogo?: string | undefined; }>
-
useHasPermission
(params: any) => AuthHook<{ error: null; success: boolean; }>
-
useListOrganizations
() => any
-
useActiveOrganization
() => any
-
useListApiKeys
() => AuthHook<ApiKey[]>
-
useListPasskeys
() => any
-
useListSessions
() => AuthHook<any[]>
-
useListDeviceSessions
() => AuthHook<any[]>
-
useAccountInfo
(params: any) => AuthHook<{ user: User; }>
-
useListAccounts
() => AuthHook<Account[]>
-
useSession
() => any
-

Usage in Components

You can access these hooks through the AuthUIContext within any component wrapped by the provider.

import { useContext } from "react";
import { AuthUIContext } from "better-auth-ui";

export function MyComponent() {
  const { hooks } = useContext(AuthUIContext);
  const { useSession } = hooks;

  const { data: session } = useSession();

  return (
    <div>{session ? `Logged in as ${session.user.name}` : "Not logged in"}</div>
  );
}

Core Hooks

useSession

Returns the current user session.

  • Returns: { data: Session | null; isPending: boolean; error: any; refetch: () => void }

useListOrganizations

Returns a list of organizations the user belongs to.

  • Returns: { data: Organization[] | null; isPending: boolean; }