BETTER-AUTH. UI
Queries

Queries

Solid Query factories and auth read helpers.

Solid queries are package runtime APIs. They return @tanstack/solid-query options and Solid hooks for Better Auth read endpoints, with shared @better-auth-ui/core cache keys.

Every supported query exposes an options factory. UI-safe queries also expose a use* hook. Session and user-scoped families additionally expose ensure*, prefetch*, and fetch* helpers for loaders and server-aware route code.

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

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

Invalidation

Keys follow an ["auth", ...] prefix, with per-user queries nested under ["auth", "user", userId, ...]. Invalidate by prefix for hierarchical cache control. Use the shared authQueryKeys factory from @better-auth-ui/core so cache entries line up regardless of which options factory produced them:

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 (useListAccounts, useAccountInfo, useListSessions, useListDeviceSessions, useListPasskeys, useListApiKeys) are keyed per-user and wait for the active session before firing — queryFn is swapped for skipToken until userId resolves. This means they drop out of the cache cleanly on sign-out and on account switching with a persister they stay isolated per user.

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