Skip to content

feat: persistent sessions with rotating remember tokens - #328

Merged
thegdsks merged 48 commits into
mainfrom
release/persistent-sessions-2026-12-02
Dec 3, 2026
Merged

thegdsks merged 48 commits into
mainfrom
release/persistent-sessions-2026-12-02

Conversation

@thegdsks

@thegdsks thegdsks commented Dec 3, 2026

Copy link
Copy Markdown
Member

What ships

Persistent sessions ("keep me signed in"), off until you set auth.session.persistent.

  • Server: a rotating remember cookie next to the session cookie, POST /auth/session/refresh, reuse detection, a grace window for parallel tabs and instances, device list, rename, forget and revoke, and refreshFromRequest for server rendered pages. Migration 0016 adds two tables.
  • Sign-in routes: remember works across password, second factor, passkey, OAuth, magic link, email code, phone, One Tap and native app exchange, including routes that answer with the token in JSON.
  • Adapters: refreshPageSession for Next.js, Hono, Express, Fastify, NestJS, Nuxt, Astro, SvelteKit, SolidStart and TanStack Start. @glinr/theauth-nextjs-auth takes a persistent option for a theAuth backend.
  • Client and React: remember on sign-in, one refresh and one retry on session_expired, tab sync, usePersistentSession(), external auth support, and remember on the theauth-go client and its query hooks.
  • Storage: Prisma models and typed methods for the two tables, and SQL Server schema support.
  • Doctor: checks for long lifetimes and a missing idle timeout.
  • SSO: sso.authorizeConnectionRoutes gates connection create, list and delete, and sso.handleLoginRequest serves only the sign-in and callback routes. The doctor reports sso.connection_routes_open when neither is in use.
  • Docs: guide, API reference, client usage, framework and Prisma page, upgrade notes, threat model, and a runnable example in examples/persistent-sessions.
  • Dependencies: workspace overrides move cross-spawn to 7.1.0 or later, ws 7.x to 7.5.14 or later and tar to 8.0.5. Zod 4, which only development tooling and agent-frameworks tests install, moves to 4.6.7.

Upgrade steps

  1. Upgrade the packages. Nothing changes for users until the feature is turned on.
  2. Make sure persistent.idleTimeoutMs (30 days by default) is longer than the session maxAge, or startup fails.
  3. Apply migration 0016. It runs at startup unless you use skipMigrations or D1. Prisma users copy the two new models. SQL Server users run applyMssqlSchema.
  4. Set auth.session.persistent with a secret of at least 32 bytes, the same on every instance.
  5. Update the client to pass remember and to refresh once on session_expired.
  6. If you use SSO, set sso.authorizeConnectionRoutes or mount sso.handleLoginRequest.

Behaviour to check once it is on: rememberMe: true no longer lengthens the session itself, password changes and resets end remembered devices, and a POST sign-in on a JSON route sets no remember cookie when its Origin is not your own or a trusted one. Full list in docs/persistent-sessions-upgrade.mdx.

Limits

  • A remember token replayed inside the grace window (30 seconds by default) gets the same successor and is not flagged at that moment.
  • If a rotation response is lost, the previous token can rotate once more after the grace window.
  • Tokens are not bound to an IP address or a device key. A refresh does not ask for the second factor again.
  • Module handleRequest routes do not receive trustedOrigins. A frontend on another origin should use the routes served by createTheAuthHandler.
  • The Prisma adapter is a standalone query layer. Rotation runs in createTheAuth.
  • The theauth-go client has no method that only refreshes (createSessionRefresher covers it), and it needs a theauth-go server that supports persistent sessions.
  • Published packages keep their zod 3 ranges. Moving them to zod 4 is a separate migration, since core builds OpenAPI from zod 3 internals and consumers would have to follow.
  • The overrides apply to this workspace only, so no published dependency range changes. tar 8 requires Node 22, and its extract() without a file now returns a promise, which the @mapbox/node-pre-gyp install command does not expect. Here that package is only used by @vercel/nft for path lookup, which does not call it.

Checks

Build (34 of 34), lint and typecheck (53 of 53) pass. The test suite reports 16974 passed, 0 failed and 590 skipped; the skips include the Postgres and MySQL persistent session suites, which need a live database. The persistent sessions example runs to the end, the docs link check passes, the generated llms files are current and the production audit gate passes.

On a busy macOS machine the Express adapter tests can fail at random when the test client reaches another local server on the same port. One full run and one push hook run hit this, and the reruns passed.

@thegdsks
thegdsks requested a review from a team as a code owner December 3, 2026 17:41
@sonarqubecloud

sonarqubecloud Bot commented Dec 3, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
4.2% Duplication on New Code (required ≤ 3%)
C Security Rating on New Code (required ≥ A)
D Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

const auth = await persistentAuth();
const app = express();
app.use(express.json());
app.use(BASE_PATH, theAuthMiddleware({ theauth: auth }));
options: SessionRefresherOptions = {},
hooks: RefresherHooks = {},
): SessionRefresher {
const base = (options.basePath ?? "/api/theauth").replace(/\/+$/, "");
@thegdsks
thegdsks merged commit 3b1bf09 into main Dec 3, 2026
15 of 19 checks passed
@thegdsks
thegdsks deleted the release/persistent-sessions-2026-12-02 branch December 3, 2026 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants