When your Better Auth server runs on a separate backend (e.g., standalone h3/Nitro project, Express, or any other server), use clientOnly mode.
export default defineNuxtConfig({
modules: ['@onmax/nuxt-better-auth'],
auth: {
clientOnly: true,
},
})
import { defineClientAuth } from '@onmax/nuxt-better-auth/config'
export default defineClientAuth({
baseURL: 'https://auth.example.com', // Your external auth server
})
Auto-detected on Vercel/Cloudflare/Netlify. For other platforms:
NUXT_PUBLIC_SITE_URL="https://your-frontend.com"
| Feature | Full Mode | Client-Only |
|---|---|---|
server/auth.config.ts | Required | Not needed |
/api/auth/** handlers | Auto-registered | Skipped |
NUXT_BETTER_AUTH_SECRET | Required | Not needed |
| Server middleware | Enabled | Skipped |
| Schema generation | Enabled | Skipped |
| Devtools | Enabled | Skipped |
| SSR session hydration | Server-side | Client-side only |
useUserSession() | Works | Works |
| Route protection | Works | Works (client-side) |
<BetterAuthState> | Works | Works |
credentials: true)SameSite=None; Secure for cross-origin requests (HTTPS required)trustedOrigins includes your frontend URLNUXT_PUBLIC_SITE_URL should be your frontend URL (for redirects). The auth server URL is configured via baseURL in app/auth.config.ts.serverAuth(), getUserSession() and requireUserSession() are not available in client-only mode since there's no local auth server.In client-only mode, session data is fetched client-side only. This means:
<BetterAuthState> component to handle loading states gracefully<template>
<BetterAuthState v-slot="{ isLoading, user }">
<div v-if="isLoading">Loading...</div>
<div v-else-if="user">Welcome, {{ user.name }}</div>
<div v-else>Please log in</div>
</BetterAuthState>
</template>
If you need SSR session hydration, consider using full mode with a local auth server instead.
┌─────────────────┐ ┌─────────────────┐
│ Nuxt App │────▶│ Auth Server │
│ (clientOnly) │ │ (Better Auth) │
│ │◀────│ │
└─────────────────┘ └────────┬────────┘
│
┌────────▼────────┐
│ Database │
└─────────────────┘