How to refetch user data client-side?

I'm updating the user object on the server-side and need to trigger an update from the client side. Is there a function, I can call from the client to refetch the session from the server?
Solution:
Yeah getSession will always hit your server, but if you have session-cookie-cache then it won't hit your DB
Jump to solution
7 Replies
Jan
JanOP2mo ago
Or is there any way, I can set a custom field from the client side and it gets updated in the session.user object?
Gingivitis
Gingivitis2mo ago
I'm having the same issue with Svelte Kit. I'm signing in on the server, and I need the client to update the session data. I've trying calling authClient.getSession(), but it doesn't seem to be updating the useSession() store, so my interface doesn't react to any changes.
Jan
JanOP2mo ago
Does anyone have an idea on how to do this? I would think that is is a rare usecase
Jan
JanOP2mo ago
refetch is available on React, but not with any other Library https://www.better-auth.com/docs/concepts/client#hooks
Client | Better Auth
Better Auth client library for authentication.
Ping
Ping2mo ago
Hey can you elaborate? If you need to refetch the session just call getSession? We will focus more towards better front-end APIs and components in the future, so for now it's mostly focused towards React to keep things simple
Jan
JanOP2mo ago
I didn‘t know that getSession refetches from the server instead of getting the data from cookie storage
Solution
Ping
Ping2mo ago
Yeah getSession will always hit your server, but if you have session-cookie-cache then it won't hit your DB

Did you find this page helpful?