@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, orRefererwithout it, must matchbaseUrl, the request’s own origin or the handler’strustedOrigins. With neither header,Sec-Fetch-Site: same-originis required. A remember cookie alone can mint a session, so this check is separate from the general cross-site one. - Transport. With an
httpsbaseUrl, plain http requests are refused. Behind a TLS terminating proxy, settrustedProxyso its forwarded protocol counts. - Rate limit.
refreshRateLimitPerMinuteper client IP.
{ "error": { "code", "message" } }.
Error codes
Device routes
All need a valid session. Without one they answer 401 withsession_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/sessionanswers{ "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-outalso 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/disableends the user’s remembered devices when it succeeds.- Sign-in routes read
rememberand 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.