Registry / web-framework / better-auth-react-query

better-auth-react-query

JSON →
library0.0.5jsnpmunverified

A TanStack React Query client wrapper for Better Auth, currently at v0.0.5. This package transforms a Better Auth client into a TanStack Query-compatible client with full TypeScript support. It automatically treats `get` and `list` methods as queries and all other methods as mutations, providing `queryOptions()` and `mutationOptions()` helpers. The package is in early development with no major release cadence. It requires `@tanstack/react-query` >= 5.0.0 and `better-auth` >= 1.4.0. Key differentiators include automatic distinction between queries and mutations, full type inference from Better Auth client configuration, and query key helpers for cache invalidation.

npm install better-auth-react-query
INSTALL
IMPORT
SIG · BETTER-AUTH-REACT-
B
better-auth-react-query
web-frameworkjavascriptv0.0.5
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createAuthQueryClient
import { createAuthQueryClient } from 'better-auth-react-query'
const { createAuthQueryClient } = require('better-auth-react-query')
Package is ESM-only; named export.
default
import betterAuthReactQuery from 'better-auth-react-query'
import { default } from 'better-auth-react-query'
No default export; use named import instead.
createAuthQueryClient
const { createAuthQueryClient } = await import('better-auth-react-query')
const createAuthQueryClient = require('better-auth-react-query').createAuthQueryClient
In CJS environments, use dynamic import; require is not supported.

Demonstrates creating an auth query client and using both queries (getSession) and mutations (signIn.email) with TanStack Query hooks.

import { createAuthQueryClient } from 'better-auth-react-query' import { createAuthClient } from 'better-auth/react' import { useQuery, useMutation } from '@tanstack/react-query' const authClient = createAuthClient() const auth = createAuthQueryClient(authClient) function Profile() { const { data: session } = useQuery(auth.getSession.queryOptions()) return <div>Welcome, {session?.user.name}</div> } function SignInForm() { const signIn = useMutation(auth.signIn.email.mutationOptions()) const handleSubmit = (e) => { e.preventDefault() const formData = new FormData(e.currentTarget) signIn.mutate({ email: formData.get('email'), password: formData.get('password'), }) } return ( <form onSubmit={handleSubmit}> <input name="email" type="email" /> <input name="password" type="password" /> <button type="submit" disabled={signIn.isPending}>Sign In</button> </form> ) }
Debug
Known issues
gotchaPackage is in early alpha (v0.0.5). API may change without notice.
fix
Pin to exact version and test upgrades.
affects: <1.0.0
gotchaRequires @tanstack/react-query >= 5.0.0. Not compatible with v4.
fix
Upgrade @tanstack/react-query to v5 or later.
affects: >=0.0.0
gotchaRequires better-auth >= 1.4.0. Older versions may break.
fix
Ensure better-auth is at least v1.4.0.
affects: >=0.0.0
gotchaMethods not starting with 'get' or 'list' are treated as mutations. If your auth client has custom methods that should be queries, they will be incorrectly wrapped.
fix
Only methods named get* or list* are queries; all others are mutations. Rename custom methods accordingly.
affects: >=0.0.0
gotchaNo native support for server-side rendering (SSR) or deferred data loading patterns (e.g., placeholderData, keepPreviousData). Must be handled manually.
fix
Implement custom query options with TanStack Query's SSR helpers.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'better-auth-react-query' or its corresponding type declarations.
Package not installed or missing from package.json.
fix
Run 'npm install better-auth-react-query' or add it to dependencies.
TypeError: createAuthQueryClient is not a function
Importing the wrong symbol (e.g., default export does not exist).
fix
Use named import: import { createAuthQueryClient } from 'better-auth-react-query'
Module not found: Can't resolve 'better-auth/react'
better-auth not installed or not configured for React.
fix
Install better-auth: 'npm install better-auth' and ensure React setup.
TypeError: auth.getSession.queryOptions is not a function
Auth client not properly wrapped; createAuthQueryClient not called.
fix
Correct usage: const auth = createAuthQueryClient(authClient); then use auth.getSession.queryOptions()
Upgrade
Version history
0.0.5latest on npm
Audit
Dependencies
@tanstack/react-queryrequiredPeer dependency; provides useQuery, useMutation, and QueryClient required by the wrapper.
better-authrequiredPeer dependency; the source auth client is created via better-auth.
Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
1
Resources
better-auth-react-query — npm install better-auth-react-query · libregistry