customSession plugin lets you store application-specific data inside every session without adding database columns. Fields live in session.metadata.custom.
Install
The plugin ships insidekavachos/auth, no extra packages needed.
Setup
Reading and writing fields
After setup, access the module through the plugin context:updateSessionFields merges with existing data. Keys not in the update are left untouched.
Hook behaviour
onSessionCreate fires inside the plugin runner’s onSessionCreate hook, the same lifecycle point used by other plugins. The returned fields are merged into session.metadata.custom. If both defaultFields and the callback define the same key, the callback wins.
REST endpoints
| Method | Path | Description |
|---|---|---|
GET | /auth/session/fields?sessionId=<id> | Read custom fields for a session |
PATCH | /auth/session/fields | Update custom fields on a session |
GET example
PATCH example
404 when the session does not exist.
Config reference
| Option | Type | Description |
|---|---|---|
defaultFields | Record<string, unknown> | Fields merged into every new session. |
onSessionCreate | async (userId, request?) => Record | Async callback; return value is merged over defaultFields. |
Storage
No migrations required. Custom data is stored in themetadata JSON column of kavach_sessions under the custom key. Existing metadata keys (such as those written by other plugins) are not affected.