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 insidekavachos/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: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
| Type | Accepted values |
|---|---|
string | Any typeof v === 'string' |
number | Any typeof v === 'number' |
boolean | true or false |
json | Any non-null value |
REST endpoints
| Method | Path | Description |
|---|---|---|
GET | /auth/users/fields?userId=<id> | Read additional fields for a user |
PUT | /auth/users/fields | Set additional fields on a user |
POST | /auth/fields/validate | Validate fields against the schema |
GET example
PUT example
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 underuser.metadata.additionalFields and session fields under session.metadata.additionalFields. Other metadata keys written by the core system or other plugins are not modified.