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.
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 anonSessionCreate 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
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 themetadata JSON column of theauth_sessions under the custom key. Existing metadata keys (such as those written by other plugins) are not affected.
Related
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.