Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How do I update additionalFields on a session?#6148

Unanswered
baseonmars asked this question inQ&A
Discussion options

I have additonalFields specified on my session as such:

export const auth = betterAuth({  // ...  session: {    additionalFields: {      activeAdvertiserId: {        type: "string",        required: false,      }    }  } //...

database schema is updated to reflect this.

How do I update the activeAdvertiserId on the session and have that re-sync with the client?

Currently I'm able to write to the session table directly but this bypasses the cookie cache and means I'm unable to use a secondary storage if I choose to. I installed the openAPI plugin but it only seems possible to update the user, not the session.

Should I be storing activeAdvertiserId on the user instead?

You must be logged in to vote

Replies: 1 comment

Comment options

Hi@baseonmars! I'mDosu and I’m helping the better-auth team.

There isn’t a built-in API in better-auth for updating session.additionalFields (like activeAdvertiserId) and having that change automatically sync with the client. Directly updating the session table bypasses the cookie cache and secondary storage, which can cause desynchronization issues, especially if you plan to use features like secondaryStorage or cookie caching reference.

The openAPI plugin only supports updating user fields, not session fields. The recommended pattern is to store fields like activeAdvertiserId on the user instead, since user updates are supported by the /update-user endpoint and are naturally reflected in the session cookie and client session state reference. After updating the user, you can trigger a session refresh on the client (for example, using the refetch method from useSession) to get the updated value.

If you must keep activeAdvertiserId on the session, you’d need to implement a custom endpoint that updates the session via the framework’s internalAdapter and then calls setSessionCookie to sync the change with the client, but this is not officially supported and can be brittle.

In summary: for reliable persistence and sync, store activeAdvertiserId on the user and update it via /update-user, then refresh the session on the client reference.

To reply, just mention@dosu.


How did I do?Good |Irrelevant |Incorrect |Verbose |Hallucination |Report 🐛 |Other  Chat with Dosu Join Discord Share on X

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
1 participant
@baseonmars

[8]ページ先頭

©2009-2025 Movatter.jp