Skip to main content
By default, theAuth allows unlimited concurrent sessions per user. The multi-session module adds a cap with a configurable overflow strategy, plus functions for listing and revoking sessions, useful for building an “active devices” settings page. It is a plain module exported from @glinr/theauth, not a plugin. It registers no HTTP routes and does not hook into sign-in on its own: you call enforceSessionLimit before creating a session, and you expose the list and revoke operations from your own routes.

Setup

lib/theauth.ts
The third argument is the low-level session manager (theauth.auth.session, or cookieSessionManager.raw if you use createCookieSessionManager).

Enforcing the cap

Call enforceSessionLimit before you create a session, and use buildSessionMetadata to record device and IP:
Sign-in handler

Overflow strategies

List sessions

listSessions(userId) returns all non-expired sessions for a user, newest first. Wire it to your own route to build an “active devices” UI.
List sessions (server)
Result shape
device and ip are only present when the session was created with metadata from buildSessionMetadata (or your own metadata with those keys). device is a short string parsed from the User-Agent header, such as Chrome on macOS. IP addresses are stored as-is, apply your own masking if required. Any other metadata keys appear under metadata. The result has no current flag, compare id with the caller’s session ID yourself.

Revoke a session

Revoke session (server)
revokeSession deletes the session by ID. It does not check who owns it, so verify that the session belongs to the signed-in user before calling it.

Revoke all other sessions

Sign out all other devices (server)
Revokes every non-expired session for the user except currentSessionId and returns the number revoked. getSessionCount(userId) returns the number of active sessions.

Configuration reference

number
default:"10"
Maximum concurrent sessions per user.
'evict-oldest' | 'reject'
default:"'evict-oldest'"
What to do when a new sign-in would exceed maxSessions.

Sessions

Core session model with cookie and JWT session details.

Cookie options

Cookie attributes and sliding expiry that affect session lifetime.

Trusted devices

Mark specific devices as trusted so your sign-in flow can skip 2FA.

GDPR compliance

Erase or export user data on request.
Last modified on October 7, 2026