Refetching session for additionalFields change

Hey, I added an additionalField to my session called activeProjectId. I didn't find something to update the session from the official API. So per a Discord conversation I update it via my ORM. Now when I call my set-active endpoint I need to update the session to reflect the change. The only way I found was $store.notfiy("$sessionSignal"). This is undocumented and is probably going to change in the future. Do you have an "right" way to update my session after a change to my session? Thanks in advance!
2 Replies
saze
saze2mo ago
You have a couple of ways you can include the additionalField to your session,you can use customSession plugin https://www.better-auth.com/docs/concepts/session-management#customizing-session-response Or inferAdditionalFieldPlugin https://www.better-auth.com/docs/concepts/typescript#inferring-additional-fields-on-client
Session Management | Better Auth
Better Auth session management.
TypeScript | Better Auth
Better Auth TypeScript integration.
lambert
lambertOP2mo ago
Thanks, I'm using inferAdditionalFieldPlugin. The problem is, when I'm changing it for a session I need to update the session on the frontend. I'm asking how to do that, not how to read the field

Did you find this page helpful?