Token Data
During the lifecycle of a request you will be able to access the data you have configured to be stored in the JWT by accessing req.user. The user object is automatically appended to the request for you.
Defining Token Data
You can specify what data gets encoded to the Cookie/JWT-Token by setting saveToJWT property on fields within your auth collection.
The JWT keys id, collection, email, sid, iat, and exp are reserved for Payload. A custom string passed to saveToJWT cannot replace these keys.
Payload signs an authVersion: 1 marker in each token's protected JWT header. This identifies tokens issued by the fixed authentication format. Tokens issued before this protection was added do not have the marker and must be replaced by signing in again; integrations must also reissue stored bearer tokens. The decoded JWT payload remains flat and keeps fields configured with saveToJWT at the same paths, and /me returns the same data for a valid new token. The version marker is not a payload field.
Using Token Data
This is especially helpful when writing Hooks and Access Control that depend on user defined fields.
Was this page helpful?