Skip to main content
Reference for persistent sessions. All types are exported from @glinr/theauth.

theauth.persistentSessions

null unless auth.session.persistent is set. Methods that take a userId act only on that user’s devices.

refresh

PersistentRefreshOutcome has rotated, session, sessionToken, rememberToken, rememberExpiresAt and family. With rotated: false, both tokens are null and you keep the ones you have. Failures carry one of the refresh error codes. Replace both stored tokens before you use either of them. A client that keeps an old remember token will trip reuse detection.

RequestRefresh

Result<{ session, rotated }> plus: refreshFromRequest reads headers only, so a request body stays unread. toWebRequest from @glinr/theauth/http takes skipBody for the same reason.

RememberOptions

RememberGrant has rememberToken, rememberExpiresAt and setCookie. RememberMethod is one of password, signup, mfa, passkey, magic_link, email_code, oauth, saml, phone or programmatic.

SessionFamilyView

Hooks

All four may be async.

HTTP routes

Paths are relative to the handler’s base path, /api/theauth by default. Responses carry Cache-Control: no-store unless noted.

Refresh route

POST /auth/session/refresh, no body. Checks, in order:
  • Origin. Origin, or Referer without it, must match baseUrl, the request’s own origin or the handler’s trustedOrigins. With neither header, Sec-Fetch-Site: same-origin is required. A remember cookie alone can mint a session, so this check is separate from the general cross-site one.
  • Transport. With an https baseUrl, plain http requests are refused. Behind a TLS terminating proxy, set trustedProxy so its forwarded protocol counts.
  • Rate limit. refreshRateLimitPerMinute per client IP.
Success:
Failures have the shape { "error": { "code", "message" } }.

Error codes

Device routes

All need a valid session. Without one they answer 401 with session_expired when a remember cookie is present, otherwise unauthorized. An unknown id, or one of another user, answers 404 not_found.

Changes to existing routes

While persistent sessions are on:
  • GET /auth/session answers { "error": "Not authenticated", "code": "session_expired" } when a remember cookie is present and no session is valid.
  • Plugin routes that require a session add "code": "session_expired" to their 401 under the same condition.
  • POST /auth/sign-out also ends the device named by the remember cookie, clears it, and answers 200 even if the session had already ended. If the device cannot be ended it answers 500 and the user should retry.
  • POST /auth/2fa/disable ends the user’s remembered devices when it succeeds.
  • Sign-in routes read remember and may set the remember and intent cookies.

Cookies

The remember cookie value is <device id>.<verifier>. Do not parse it and do not log it.
Last modified on December 3, 2026