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:Jump to solution
Yeah getSession will always hit your server, but if you have session-cookie-cache then it won't hit your DB
7 Replies
Or is there any way, I can set a custom field from the client side and it gets updated in the session.user object?
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.
Does anyone have an idea on how to do this? I would think that is is a rare usecase
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.
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
I didn‘t know that getSession refetches from the server instead of getting the data from cookie storage
Solution
Yeah getSession will always hit your server, but if you have session-cookie-cache then it won't hit your DB