Production requires these environment variables:
# Required: 32+ character secret for session encryption
NUXT_BETTER_AUTH_SECRET="your-32-character-secret-here-minimum"
# Optional: Auto-detected on Vercel/Cloudflare/Netlify
NUXT_PUBLIC_SITE_URL="https://your-app.com"
# OAuth provider credentials (if using)
GOOGLE_CLIENT_ID="..."
GOOGLE_CLIENT_SECRET="..."
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
The secret must be at least 32 characters. Shorter secrets will cause the module to throw an error.
NUXT_BETTER_AUTH_SECRET is set and 32+ charactersNUXT_PUBLIC_SITE_URL set (or using Vercel/Cloudflare/Netlify auto-detection)NODE_ENV=production is set (disables devtools)Route rules and definePageMeta are for UX (redirects). Always protect API endpoints with requireUserSession:
export default defineEventHandler(async (event) => {
const { user } = await requireUserSession(event)
return { data: 'protected' }
})
The module does not include built-in rate limiting. Implement rate limiting at the infrastructure level or use a middleware:
import { getRequestIP } from 'h3'
const requests = new Map<string, number[]>()
const WINDOW_MS = 60_000 // 1 minute
const MAX_REQUESTS = 100
export default defineEventHandler((event) => {
if (!event.path.startsWith('/api/auth'))
return
const ip = getRequestIP(event) || 'unknown'
const now = Date.now()
const windowStart = now - WINDOW_MS
const timestamps = (requests.get(ip) || []).filter(t => t > windowStart)
timestamps.push(now)
requests.set(ip, timestamps)
if (timestamps.length > MAX_REQUESTS) {
throw createError({ statusCode: 429, message: 'Too many requests' })
}
})
For production, consider using Cloudflare rate limiting or a Redis-backed solution.
When deploying with NuxtHub:
@nuxthub/core is listed before @onmax/nuxt-better-auth in modulesexport default defineNuxtConfig({
modules: [
'@nuxthub/core', // Must be first
'@onmax/nuxt-better-auth',
],
})
Your secret is too short. Generate a new one using the command above.
The module auto-detects URLs on Vercel, Cloudflare Pages, and Netlify. For other platforms, set NUXT_PUBLIC_SITE_URL to your production domain.
Ensure your OAuth provider's authorized redirect URIs include:
https://your-app.com/api/auth/callback/googlehttps://your-app.com/api/auth/callback/githubDevTools are automatically disabled in production (NODE_ENV=production). The /api/_better-auth/* endpoints and /__better-auth-devtools page are not registered.