Getting Started
Client Setup
Configure the client-side authentication client.
Prompt
Set up the client auth config for @onmax/nuxt-better-auth.
- Create `app/auth.config.ts` with a default export using `defineClientAuth` from `@onmax/nuxt-better-auth/config`
- Object syntax: `defineClientAuth({})` or function syntax: `defineClientAuth(({ siteUrl }) => ({}))`
- Add client plugin equivalents for every server plugin (e.g. `adminClient()` from `better-auth/client/plugins`)
- The module calls the factory with the correct `baseURL` at runtime
- `useUserSession()` is auto-imported and provides `user`, `session`, `loggedIn`, `ready`, `signIn`, `signUp`, `signOut`
Read more: https://better-auth.nuxt.dev/raw/getting-started/client-setup.md
Source: https://github.com/nuxt-modules/better-auth
Create the Client Config
Create app/auth.config.ts with a default export using defineClientAuth.
The defineClientAuth helper supports two syntaxes: an object for simple configurations, or a function when you need access to context like the resolved site URL.
app/auth.config.ts
import { defineClientAuth } from '@onmax/nuxt-better-auth/config'
// Object syntax (simplest)
export default defineClientAuth({})
// Function syntax (access context)
export default defineClientAuth(({ siteUrl }) => ({
// siteUrl contains the resolved base URL
}))
The helper creates a factory function that the module calls with the correct
baseURL at runtime.Using Plugins
If you added a plugin in your server config (server/auth.config.ts), make sure to add its client equivalent here.
app/auth.config.ts
import { defineClientAuth } from '@onmax/nuxt-better-auth/config'
import { adminClient } from 'better-auth/client/plugins'
export default defineClientAuth({
plugins: [
adminClient() // Must match the server plugin
]
})
Common Plugin Combinations
Admin + Two Factor
app/auth.config.ts
import { defineClientAuth } from '@onmax/nuxt-better-auth/config'
import { adminClient, twoFactorClient } from 'better-auth/client/plugins'
export default defineClientAuth({
plugins: [adminClient(), twoFactorClient()]
})