During build, the module reads server/auth.config.ts and generates the auth handler. If using NuxtHub, it also generates the database schema automatically.
The module injects a catch-all API handler at /api/auth/**. This handler processes all authentication requests (login, logout, session fetching) using the configuration provided in server/auth.config.ts.
On the client side, useUserSession initializes the Better Auth client. It establishes a reactive connection to the session state, ensuring that your UI updates immediately when a user logs in or out.
| Feature | What it provides | Side |
|---|---|---|
| Server handler | Mounts Better Auth at /api/auth/* | Server |
| Composables | useUserSession() for reactive state | Client |
| Server utils | serverAuth(), getUserSession(event), etc. | Server |
| Route protection | routeRules.auth and definePageMeta({ auth }) | Both |
| Type augmentation | Inferred AuthUser and AuthSession types | Build |
auth rule in routeRules or page meta/api/auth/sign-in/emailuseUserSession() reads session from cookie, updates reactive state