Skip to main content
Better Auth integrates with Nuxt through a server event handler and a Vue-aware auth client. Before you start, make sure you have a Better Auth instance configured. If you haven’t done that yet, check out the installation.

Create an API route

Create a catch-all server route at server/api/auth/[...all].ts. Use Nuxt’s defineEventHandler and toWebRequest helpers to bridge the Nitro request into Better Auth’s web-standard handler.
server/api/auth/[...all].ts
You can change the base path in your Better Auth configuration, but /api/auth is the recommended default.

Create a client

Create an auth client instance and export it from a shared module. Import from better-auth/vue to get Vue-specific reactive helpers.
lib/auth-client.ts

useSession composable

The useSession composable returns a reactive reference to the current session. Use it directly in component <script setup> blocks.
components/UserMenu.vue

SSR usage

When using Nuxt SSR, pass useFetch to useSession so the session is fetched on the server and hydrated on the client without an extra round-trip.
pages/index.vue

Server-side session access

The auth.api object exposes every Better Auth endpoint as a callable function. Access the session from any server route by passing the event headers.
server/api/me.ts

Route middleware

Use the auth client inside a Nuxt route middleware to protect pages. Calling useSession with useFetch ensures the session check runs on the server during SSR.
middleware/auth.global.ts

Resources