createTheAuthHandler through a framework adapter is enough for the refresh route and the device routes. This page covers the code that runs outside those routes: page gates, a Next.js app in front of a separate theAuth backend, and Prisma schemas.
Page gates
Every framework adapter below exportsrefreshPageSession. It returns the request’s live session, or refreshes from the remember cookie, using the framework’s own request and cookie types.
trustedOrigins adds origins that a non-GET request may come from. The Express, Fastify, NestJS and Nuxt gates also take trustProxy, which believes X-Forwarded-Proto and X-Forwarded-Host. Set it behind a TLS terminating proxy.
Call a gate only where Set-Cookie reaches the browser. A Next.js Server Component cannot set cookies, so use middleware on the Node.js runtime or a route handler. refreshPageSession throws when auth.session.persistent is not set.
Without one of these adapters, call persistentSessions.refreshFromRequest yourself.
Next.js app with a theAuth backend
@glinr/theauth-nextjs-auth runs in a Next.js app whose backend is a separate server. When that backend is theAuth with persistent sessions, set persistent.
auth.config.ts
/api/theauth, and the backend must list appUrl in its trusted origins. persistent.sessionCookie and persistent.rememberCookie name the backend’s cookies if you changed them.
- Sign in on the server with
remember: truein the body. Pass the backend response toadoptBackendSession(authConfig, response)in a server action, or tosetSessionCookiesFromBackend(nextResponse, response, authConfig)in a route handler. The adapter’s refresh cookie then holds the backend’s remember token. A sign-in withoutrememberremoves an earlier one. withAuthis the page gate. It refreshes for page navigations from your own app, never for/apiroutes, subresources or cross-site navigations. If the backend is unreachable, a protected page without a live session answers 503 and nothing is cleared.export const POST = createRefreshRouteHandler(authConfig)gives client code a refresh route. It answers 401 when the sign-in is over, 403 when refused and 503 on an outage.refreshSessiondoes nothing in a Server Component, because the rotated cookies could not be saved there.- Sign-out sends the remember token to the backend, so the device ends even after the session lapsed.
persistent option the adapter behaves as before.
Prisma
@glinr/theauth-prisma ships TheAuthSessionFamily and TheAuthSessionFamilyToken, which match migration 0016. Copy both models from node_modules/@glinr/theauth-prisma/src/schema.prisma into your schema, then:
@db.Text to userAgent and label. If createTheAuth already created the tables, add the models anyway so a later prisma db push does not treat them as drift.
The adapter exposes typed methods for the two tables, such as listSessionFamilies, revokeSessionFamily and eraseSessionFamilies. deleteUser erases a user’s device rows when the models exist. The adapter is a standalone query layer: refresh and rotation run in createTheAuth, so prefer theauth.persistentSessions for anything that changes a device. A revocation made through Prisma marks the device row only and leaves its current session running.
A client generated from an older schema still type checks and works. Calling a device method on it throws an error that names the missing models.
SQL Server
applyMssqlSchema creates the two tables on its next run. It alters no existing table.