Hooks
Zudoku exposes a set of React hooks that let you read and interact with the runtime state of your
site from custom components, MDX pages, plugins, and slots. All hooks
are available from the zudoku/hooks entry point.
Code
useAuth
The useAuth hook is the primary way to interact with authentication in Zudoku. It returns the
current auth state along with the actions needed to sign users in and out. It works with any of the
supported authentication providers.
Code
Returned values
| Property | Type | Description |
|---|---|---|
isAuthEnabled | boolean | true if an authentication provider is configured in zudoku.config.ts. When false, the action methods will throw if called. |
isAuthenticated | boolean | Whether a user is currently signed in. |
isPending | boolean | true while the provider is still initializing or restoring a session. Use this to render loading states and avoid flashing UI. |
profile | UserProfile | null | The authenticated user's profile, or null when signed out. See User profile. |
providerData | ProviderData | null | Raw provider-specific data (for example the Supabase session or Firebase user). Useful when you need access to provider-only features. |
login | (options?: AuthActionOptions) => Promise<void> | Starts the sign-in flow. Redirects back to the current page by default. |
logout | () => Promise<void> | Signs the user out. |
signup | (options?: AuthActionOptions) => Promise<void> | Starts the sign-up flow, if the provider supports it. Redirects back to the current page by default. |
AuthActionOptions accepts:
Code
User profile
When isAuthenticated is true, profile is populated with the fields returned by the provider's
user info endpoint:
Code
Example: sign-in button
Code
Example: gating content
Code
For route-level gating, prefer the declarative protected routes configuration.
useVerifiedEmail
Returns the current user's email verification state and exposes helpers to refresh it or request a new verification email. Use this in components that show verification banners or block actions until the user has verified their address.
Code
| Property | Type | Description |
|---|---|---|
email | string | undefined | The user's email address, if any. |
isVerified | boolean | undefined | Whether the provider reports the email as verified. undefined when no profile is available (e.g. signed out or pending). |
supportsEmailVerification | boolean | true when the provider implements a requestEmailVerification method. |
refresh | () => void | Re-fetch the user profile from the provider — useful after the user verifies in another tab. |
requestEmailVerification | (options?: AuthActionOptions) => Promise<void> | Triggers the provider's "resend verification email" flow. |
The hook automatically refreshes the profile when the window regains focus so isVerified updates
after the user completes verification elsewhere.
useRefreshUserProfile
Low-level hook that re-fetches the authenticated user's profile from the configured provider. Most
applications do not need to call this directly — useAuth already invokes it, and
useVerifiedEmail exposes a more ergonomic refresh(). Reach for it when you need fine-grained
control over the underlying React Query.
Code
It returns the full
React Query UseQueryResult.
useZudoku
Returns the global ZudokuContext — the object that holds navigation, auth,
plugins, the React Query client, and user-configured options. Use it when you need access to app
configuration that isn't exposed by a more specific hook.
Code
Must be called inside the ZudokuProvider (i.e. inside any Zudoku page or slot). Calling it outside
throws.
useEvent
Subscribes to Zudoku events (such as navigation or authentication changes) with automatic cleanup. See the Events page for the full guide and the list of available events.
Code
useExposedProps
Convenience wrapper around React Router's hooks. Returns the props Zudoku passes to custom-page
navigation entries, so you get the same shape whether you're writing a page component or a slot.
Code
useCache
Invalidates Zudoku's internal React Query caches. Today this supports API_IDENTITIES, which is
useful when you change something that affects the identities available to the API playground (for
example after a user creates a new API key).
Code
Re-exported hooks
For convenience, Zudoku re-exports two hooks from its underlying libraries:
useThemefromnext-themes— read or change the active color scheme (light,dark, orsystem).useMDXComponentsfrom@mdx-js/react— access the MDX component mapping when rendering MDX content inside a custom component.
Code