Skip to main content
The additionalFields plugin lets you attach typed custom data to users and sessions without writing migrations. Fields are stored in the metadata JSON column of kavach_users and kavach_sessions.

Install

Ships inside kavachos/auth, no extra packages needed.

Setup

Define a schema once when creating your KavachOS instance:

Reading and writing user fields

setUserFields merges with existing fields. Previously stored keys not present in the update are preserved.

Reading and writing session fields

Validation

Validate a field map before writing, or in a request handler:
Rules enforced during validate() (and automatically on every setUserFields / setSessionFields call):
  • Required fields must be present.
  • Field values must match the declared type.
  • Fields not in the schema are rejected.

Field types

REST endpoints

GET example

PUT example

Returns 422 when validation fails. Returns 404 when the user does not exist.

Validate example

Schema reference

Storage

No database migrations are needed. User fields are stored under user.metadata.additionalFields and session fields under session.metadata.additionalFields. Other metadata keys written by the core system or other plugins are not modified.
Last modified on April 18, 2026