BETTER-AUTH. UI
Queries

Queries

Solid Query factories and auth read helpers.

Solid query APIs provide options and hooks for Better Auth read endpoints. They use shared cache keys from @better-auth-ui/core.

Each supported query provides an options factory. Queries that are safe for components also provide a use* hook.

Session and user queries also provide ensure*, prefetch*, and fetch* helpers for route loaders.

import { useSession } from "@better-auth-ui/solid"
import { sessionOptions } from "@better-auth-ui/core"

const sessionQuery = sessionOptions(authClient)
const session = useSession(authClient, () => ({ enabled: !import.meta.env.SSR }))

Invalidation

All keys start with ["auth", ...]. Queries for one user use the ["auth", "user", userId, ...] prefix.

Invalidate a prefix to control the related cache entries. Use authQueryKeys from @better-auth-ui/core to create consistent keys:

import { authQueryKeys } from "@better-auth-ui/core"

queryClient.invalidateQueries({ queryKey: authQueryKeys.all })
queryClient.invalidateQueries({ queryKey: authQueryKeys.user(userId) })
queryClient.invalidateQueries({ queryKey: authQueryKeys.session })

Per-user queries

Settings queries use a separate cache key for each user. They wait for the session before they start.

Solid hooks remain disabled until their required user values resolve. Consumer enabled controls still apply.

This design removes stale data after sign-out. It also isolates data after an account switch.

Escape hatch

For read-style endpoints without a purpose-built Solid helper, use useAuthQuery in components or authQueryOptions where Solid Query takes an options object.

import { useAuthQuery } from "@better-auth-ui/solid"

const result = useAuthQuery(
  authClient.magicLink.list,
  ["auth", "magicLink", "list"],
  { query: { limit: 20 } }
)

Available queries

Auth

Settings

Organization

Last updated on

On this page