How can i set custom data to the session token?
In the
auth.ts
file I wanna set some custom data to the session-token cookie so the data can be synchronously retrieved on the server side without using:
await auth.api.getSession({
headers: await headers(),
});
which seems to do a DB call to get the data.
The typescript autocomplete led me this:
session: {
expiresIn: 60 * 60 * 24 * 7,
updateAge: 60 * 60 * 24,
fields: {
userId: "userId"
},
},
the way the fileds seems to work is it accepts the session schema's fields like userId
and the value it accepts has to be the userId: NotNull<PgUUIDBuilderInitial<"user_id">>
but as a value (i.e, userId: "userId"
).
but then it I proceed with this the value of userId is just "userId" when i try to access the userId data from another place. Is there any way to dynamically set the userId in the cookie itself based on the user that is in session?0 Replies