Skip to main content
The customSession plugin lets you store application-specific data on a session without adding database columns. Fields live in session.metadata.custom, and you read and update them with the module or the REST endpoints below.
defaultFields and onSessionCreate are registered as a plugin onSessionCreate hook, but theAuth’s session managers and sign-in modules do not currently invoke plugin hooks. Creating a session through theauth.auth.session.create(...) does not populate metadata.custom by itself. Until that wiring exists, write the initial fields yourself with updateSessionFields right after you create the session.

Install

The plugin ships inside @glinr/theauth/auth, no extra packages needed.

Setup

Reading and writing fields

After setup, access the module through the plugin context (it is not a property of the instance):
updateSessionFields merges with existing data. Keys not in the update are left untouched. It throws when the session does not exist.

Hook behaviour

The plugin declares an onSessionCreate hook that merges defaultFields and the result of your onSessionCreate callback (callback wins on a key clash) into { custom: ... }. The hook is collected into the plugin registry, but theAuth does not call it when sessions are created today (see the warning above). Treat defaultFields and onSessionCreate as inert until it is wired up.

REST endpoints

GET example

PATCH example

Returns 404 when the session does not exist. Both endpoints require an authenticated user, but they do not check that the sessionId belongs to that user, so any signed-in caller who knows a session ID can read or change its custom fields. Treat session IDs as private, or put your own ownership check in front of these routes.

Config reference

Storage

No migrations required. Custom data is stored in the metadata JSON column of theauth_sessions under the custom key. Existing metadata keys (such as those written by other plugins) are not affected.

Sessions

Core session model: cookie sessions, JWT tokens, and lifecycle management.

Additional fields

Attach custom columns to users instead of sessions.

Hooks

Lifecycle hooks you can attach to your instance.

Cookie options

Cookie attributes for cross-subdomain and production setups.
Last modified on October 7, 2026