Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
dd234c6
docs: add a roadmap page with persistent sessions and planned features
thegdsks Dec 3, 2026
8859a0c
feat: add persistent sessions config types and migration 0016
thegdsks Dec 3, 2026
d20cada
feat: add persistent session config validation and remember token der…
thegdsks Dec 3, 2026
65d56a5
feat: record the previous session on a session family
thegdsks Dec 3, 2026
fc58bd4
feat: add persistent session store, refresh state machine and routes
thegdsks Dec 3, 2026
32efb81
feat: wire persistent sessions into createTheAuth, routes and revocat…
thegdsks Dec 3, 2026
89ab842
test: run the persistent sessions conformance suite and HTTP behaviou…
thegdsks Dec 3, 2026
8635993
test: type the conformance OAuth provider
thegdsks Dec 3, 2026
46a4bb4
docs: remove the roadmap page
thegdsks Dec 3, 2026
de18364
fix: erase remembered devices on anonymize and ignore backup code use…
thegdsks Dec 3, 2026
524f09e
chore: add a changeset for persistent sessions
thegdsks Dec 3, 2026
923137d
feat: add persistent session refresh, remember and tab sync to the cl…
thegdsks Dec 3, 2026
b3bc460
feat: add usePersistentSession and the remember option to react
thegdsks Dec 3, 2026
44d7590
feat: document persistent sessions in the client packages and add a c…
thegdsks Dec 3, 2026
0194924
fix: refuse a dead remember device beside another live session
thegdsks Dec 3, 2026
d61053f
fix: run all user revocations when ending remembered devices fails
thegdsks Dec 3, 2026
54186a7
fix: keep remembered devices when a password hash is upgraded on sign-in
thegdsks Dec 3, 2026
a521a31
fix: refuse a session lifetime that outlasts the remember idle timeout
thegdsks Dec 3, 2026
eacf510
fix: tie the remember intent to the sign-in flow that asked for it
thegdsks Dec 3, 2026
2647d92
Merge remote-tracking branch 'origin/main' into prep/persistent-sessi…
thegdsks Dec 3, 2026
fd54040
chore: merge persistent sessions client work
thegdsks Dec 3, 2026
39f3c3e
fix: remember sign-ins on module routes and routes that answer in JSON
thegdsks Dec 3, 2026
c405687
fix: finish a forced password reset when remembered devices cannot be…
thegdsks Dec 3, 2026
08861ff
docs: describe persistent session sign-in routes and failure behaviou…
thegdsks Dec 3, 2026
85b3e5c
Merge remote-tracking branch 'origin/main' into docs/persistent-sessi…
thegdsks Dec 3, 2026
cae2ebb
Merge remote-tracking branch 'origin/main' into local/persistent-adap…
thegdsks Dec 3, 2026
174c17d
feat: gate SSO connection routes and add handleLoginRequest
thegdsks Dec 3, 2026
aa90dcf
feat: add doctor rule sso.connection_routes_open
thegdsks Dec 3, 2026
959f251
docs: mount SSO sign-in with handleLoginRequest
thegdsks Dec 3, 2026
1cc5191
feat: add persistent session checks to the doctor
thegdsks Dec 3, 2026
7cd7b2e
fix: end dormant devices when other sessions are revoked through mult…
thegdsks Dec 3, 2026
af6cef6
docs: add a runnable persistent sessions example
thegdsks Dec 3, 2026
4470684
docs: add persistent sessions guide, API reference, client usage, upg…
thegdsks Dec 3, 2026
9a9a756
Merge branch 'prep/persistent-sessions-pr' into docs/persistent-sessi…
thegdsks Dec 3, 2026
9c758ff
docs: note how One Tap and magic link requests ask to be remembered
thegdsks Dec 3, 2026
1682247
feat: add persistent session families to the prisma adapter
thegdsks Dec 3, 2026
de25422
test: run persistent sessions against postgres, mysql and the sql ser…
thegdsks Dec 3, 2026
423f3a3
feat: add persistent session page gates to the framework adapters
thegdsks Dec 3, 2026
b9c022f
feat: support persistent session backends in the nextjs auth adapter
thegdsks Dec 3, 2026
031ae3d
Merge branch 'prep/persistent-sessions-pr' into local/persistent-adap…
thegdsks Dec 3, 2026
4faa8b5
feat: carry remember and refresh through the go client, query hooks a…
thegdsks Dec 3, 2026
785a857
Merge branch 'local/persistent-adapters' into prep/persistent-session…
thegdsks Dec 3, 2026
e3ec641
fix: ignore remember requests from foreign origins on JSON sign-in re…
thegdsks Dec 3, 2026
92c0099
docs: cover adapters, prisma, nextjs auth and the go client for persi…
thegdsks Dec 3, 2026
01a5bc6
fix: require cross-spawn 7.1.0 or later across the workspace
thegdsks Dec 3, 2026
2920372
fix: require ws 7.5.14 or later for the 7.x line
thegdsks Dec 3, 2026
148582e
fix: move the build toolchain to tar 8
thegdsks Dec 3, 2026
9fcdb4b
fix: use zod 4.6.6 or later wherever zod 4 is installed
thegdsks Dec 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .changeset/persistent-sessions-adapters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
"@glinr/theauth": minor
"@glinr/theauth-astro": minor
"@glinr/theauth-express": minor
"@glinr/theauth-fastify": minor
"@glinr/theauth-hono": minor
"@glinr/theauth-nestjs": minor
"@glinr/theauth-nextjs": minor
"@glinr/theauth-nextjs-auth": minor
"@glinr/theauth-nuxt": minor
"@glinr/theauth-solidstart": minor
"@glinr/theauth-sveltekit": minor
"@glinr/theauth-tanstack": minor
"@glinr/theauth-prisma": minor
---

Persistent sessions in the framework and storage adapters. Each framework adapter exports `refreshPageSession` for server rendered page gates, in the framework's own request and cookie types. `refreshFromRequest` now also returns the parsed cookies and the updated `Cookie` header, and `toWebRequest` takes `skipBody`. `multiSession.revokeOtherSessions` also ends remembered devices that have no live session.

`@glinr/theauth-nextjs-auth` takes a `persistent` option for a theAuth backend: it carries the remember cookie through sign-in, refreshes from the middleware page gate and `createRefreshRouteHandler`, and forwards it on sign-out. Nothing changes without the option.

The Prisma adapter has `TheAuthSessionFamily` and `TheAuthSessionFamilyToken` models matching migration 0016, with typed methods for them. Copy the models, migrate and regenerate the client to use them. Downgrading: older versions ignore both tables, so they can stay; drop `theauth_session_family_tokens` before `theauth_session_families` if you remove them, which signs remembered devices out.

SQL Server: `applyMssqlSchema` creates the two tables on its next run. It never alters existing tables, and none are altered here.
8 changes: 8 additions & 0 deletions .changeset/persistent-sessions-clients.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@glinr/theauth-client": minor
"@glinr/theauth-react": minor
---

Client support for persistent sessions. `signIn` takes `{ remember }`, the session store has `refreshSession()`, `fetch()` and `isResolved()`, and `createSessionRefresher()` is available on its own. When the server answers `session_expired`, the client refreshes once (one request per tab, serialized across tabs) and retries once. Network errors and 5xx answers on refresh never sign the user out. Tabs now share sign in and sign out through `BroadcastChannel` or storage events; pass `tabs: { sync: false }` to turn that off. React adds `usePersistentSession()`, which shows nothing signed in until the session is known. A server without persistent sessions never sends `session_expired`, so no refresh requests are made against it.

`createTheAuthGoClient` takes `remember` on `login`, `signup` and `passkeys.login`, and refreshes and retries once on `session_expired` for cookie requests. `createSessionRefresher` takes `refreshPath` and reads the theauth-go error shape. `useLogin` and `usePasskeys().login` pass `remember` on. External provider mode adds the choice to the login redirect, refreshes when the user route answers `session_expired`, and exposes `refreshSession` and `authFetch` when `refreshPath` is set.
5 changes: 5 additions & 0 deletions .changeset/persistent-sessions-doctor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@glinr/theauth-cli": minor
---

`theauth doctor` and `theauth doctor --security` check persistent session lifetimes. `persistent.lifetime_long` fires when `idleTimeoutMs` is over 30 days or `absoluteLifetimeMs` over 90 days. `persistent.idle_missing` fires when `idleTimeoutMs` is not shorter than `absoluteLifetimeMs`. The security linter reports them as `sec.persistent.lifetime_long` and `sec.persistent.idle_missing`. Move the two ceilings with `THEAUTH_DOCTOR_PERSISTENT_MAX_IDLE_MS` and `THEAUTH_DOCTOR_PERSISTENT_MAX_ABSOLUTE_MS`.
13 changes: 13 additions & 0 deletions .changeset/persistent-sessions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"@glinr/theauth": minor
---

Adds opt-in persistent sessions ("keep me signed in") under `auth.session.persistent`. A sign-in that sends `remember: true` (or `rememberMe`) gets a long-lived remember cookie next to the normal session cookie. When the session ends, `POST /auth/session/refresh` trades the remember cookie for a new session and a rotated remember token. Rotations are deterministic, so parallel tabs and several instances get identical cookies; a reused old token ends the whole device sign-in. Devices can be listed, renamed, forgotten and revoked through `GET`, `PATCH` and `DELETE /auth/session-families` and `auth.persistentSessions`. When persistent sessions are on and a request carries a remember cookie, an expired session answers with the code `session_expired` so clients know to refresh once and retry. Migration 0016 creates two new tables and runs only when the feature is enabled. Nothing changes when `auth.session.persistent` is not set.

The choice also works on sign-in routes that answer with the session token in JSON: `handleRequest` of the username, magic link, email code and phone modules, and the magic link, email code, One Tap and native app exchange routes of the plugins. These set the remember cookie only, so there is no need to call `persistentSessions.remember()` as well. Send POST requests as `application/json`. A POST whose `Origin` or `Referer` is not your `baseUrl`, the request origin or a trusted origin sets no remember cookie. A GET magic link verify takes `remember` from the query only on a request from your own origin. A link opened from an email uses the choice made when the link was requested in the same browser.

Things to check when you turn it on:

- Startup fails when `persistent.idleTimeoutMs` is not longer than the session `maxAge`.
- `admin.unbanUser` and SCIM reactivation fail, and the user stays disabled, if their remembered devices cannot be ended.
- A SCIM `PATCH` with `active: false` that leaves the ban flag off answers with an error if remembered devices cannot be ended, so the identity provider retries. Sessions and MCP access are still revoked on that attempt.
6 changes: 6 additions & 0 deletions .changeset/sso-connection-route-authorizer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@glinr/theauth": minor
"@glinr/theauth-cli": minor
---

SSO connection routes can now be gated. Set `sso.authorizeConnectionRoutes` to refuse connection create, list and delete with a 403, or mount the new `sso.handleLoginRequest`, which serves only the SAML and OIDC login and callback routes. Without an authorizer `handleRequest` behaves as before and logs one warning, and `theauth doctor` reports `sso.connection_routes_open`.
27 changes: 25 additions & 2 deletions docs/auth/sso.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ icon: shield-halved

## Setup

Configure your identity providers when creating the theAuth instance. `theauth.sso` is `null` unless the `sso` key is passed, so use `theauth.sso!.` (or `?.`) in your code. There is no SSO plugin: routes are served through `theauth.sso.handleRequest`.
Configure your identity providers when creating the theAuth instance. `theauth.sso` is `null` unless the `sso` key is passed, so use `theauth.sso!.` (or `?.`) in your code. There is no SSO plugin: mount `theauth.sso.handleLoginRequest` for sign-in, as shown under [Endpoints](#endpoints).

<Tabs>
<Tab title="SAML 2.0">
Expand Down Expand Up @@ -173,7 +173,30 @@ OIDC discovery is fetched automatically from `issuer/.well-known/openid-configur

## Endpoints

Served by `theauth.sso.handleRequest(request)`. The handler does no authentication of its own, so put your own admin check in front of the connection routes.
For sign-in, mount `theauth.sso.handleLoginRequest`. It serves only the SAML and OIDC login and callback routes, and returns `null` for everything else, including connection management.

```ts
async function handler(request: Request): Promise<Response> {
const response = await theauth.sso!.handleLoginRequest(request); // [!code highlight]
return response ?? new Response('Not found', { status: 404 });
}
```

`theauth.sso.handleRequest(request)` serves those routes plus connection create, list and delete. If you mount it, set `authorizeConnectionRoutes`:

```ts
const theauth = await createTheAuth({
database: { provider: 'sqlite-native', url: 'theauth.db' },
sso: {
saml: [okta],
authorizeConnectionRoutes: async (request) => isAdminRequest(request), // your own check // [!code highlight]
},
});
```

The connection routes answer `403` with code `SSO_CONNECTION_ROUTE_FORBIDDEN` when the function resolves `false` or throws. It receives a clone of the request, so it can read the body. The check is a yes or no for the whole request: to limit an admin to one org, read the org id (or connection id) from the request and compare it yourself.

Without `authorizeConnectionRoutes`, `handleRequest` leaves the connection routes open to any caller. It logs one warning through your configured `logger`, and `theauth doctor` reports `sso.connection_routes_open`. The direct methods (`createConnection`, `listConnections`, `removeConnection`) are never gated.

| Method | Path | Description |
|--------|------|-------------|
Expand Down
3 changes: 3 additions & 0 deletions docs/cli-tools.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,14 @@ When `theauth.config.mjs` or `theauth.config.js` is present, the doctor reads it
| `cookie.insecure_http` | fail | `baseUrl` is plain http on a host that is not localhost |
| `webauthn.rpid_mismatch` | fail | `passkey.rpId` is neither the `baseUrl` host nor a parent domain of it |
| `session.ttl_long` | warn | `auth.session.maxAge` is over 30 days |
| `persistent.lifetime_long` | warn | `auth.session.persistent` has `idleTimeoutMs` over 30 days or `absoluteLifetimeMs` over 90 days. Ceilings: `THEAUTH_DOCTOR_PERSISTENT_MAX_IDLE_MS`, `THEAUTH_DOCTOR_PERSISTENT_MAX_ABSOLUTE_MS` |
| `persistent.idle_missing` | warn | `auth.session.persistent.idleTimeoutMs` is not shorter than `absoluteLifetimeMs`, so devices have no effective idle limit |
| `network.trusted_proxies_empty` | warn | `trustForwardedHeaders` is on and `trustedProxy` names no proxy |
| `mfa.none_enabled` | warn | username or session sign-in is configured with neither `totp` nor `passkey` |
| `password.min_length_low` | warn | `username.password.minLength` is under 12 (default 8) |
| `password.pbkdf2_iterations_low` | warn | an iteration override (`username`, `passwordReset`, or `THEAUTH_PBKDF2_ITERATIONS`) resolves below 600000 |
| `saml.tracker_in_memory` | warn | SAML providers are set with neither `sso.storage` nor `secondaryStorage` |
| `sso.connection_routes_open` | warn | `sso` is configured without `sso.authorizeConnectionRoutes`, so `sso.handleRequest` would serve connection create, list and delete to any caller |
| `mcp.offline_no_jti_denylist` | warn | MCP revocation mode is `offline` (config or `THEAUTH_MCP_REVOCATION_MODE`) and no `mcp.jtiDenylist` is set |
| `cimd.no_host_allowlist` | warn | `mcp.clientIdMetadataDocuments` is enabled with no `allowedHosts` and no `resolver` |
| `mcp.consent_page_missing` | warn | MCP is enabled with no `mcp.consentPage`, so codes are issued without a consent screen |
Expand Down
6 changes: 6 additions & 0 deletions docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@
"sessions",
"jwt-sessions",
"session-hardening",
"persistent-sessions",
"persistent-sessions-api",
"persistent-sessions-client",
"persistent-sessions-adapters",
"persistent-sessions-upgrade",
"persistent-sessions-threat-model",
"cookies",
"one-time-tokens",
"secondary-storage"
Expand Down
17 changes: 17 additions & 0 deletions docs/errors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,23 @@ The MCP module returns `Result` errors with these codes. The token, registration
| `GATEWAY_TIMEOUT` | 504 | Gateway only: the upstream did not respond in time. |
| `INTERNAL_ERROR` | 500 | An unexpected error occurred. Check server logs for details. |

## Persistent session codes

These appear only when [persistent sessions](/persistent-sessions) are on.

| Code | Status | Meaning |
|------|--------|---------|
| `session_expired` | 401 | No valid session, but a remember cookie is present. Refresh once and retry. |
| `remember_invalid` | 401 | The remember token is unknown, or its device ended. |
| `remember_expired` | 401 | The device passed its idle timeout or absolute lifetime. |
| `remember_reused` | 401 | An old token came back and the device was ended. |
| `refresh_denied` | 403 | The account or your `check` hook refused the refresh. |
| `refresh_unavailable` | 503 | Temporary failure, nothing was revoked. |
| `csrf_origin_rejected` | 403 | The refresh request's origin is not trusted. |
| `insecure_transport` | 403 | Refresh over plain http with an `https` base URL. |

See the [API reference](/persistent-sessions-api#error-codes) for which cookies each one clears.

## Related

<CardGroup cols={2}>
Expand Down
Loading
Loading