Make it possible to setSession on client session managment #1755

Closed
opened 2026-03-13 09:01:14 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @GitonioDev on GitHub (Aug 22, 2025).

Is this suited for github?

  • Yes, this is suited for github

When using a server side arch like remix and you want to server sidely check if a user is authenticated then you would use a loader with the server side getSession with headers and conditionally redirect based on the logged in status because you then already fetched the session it would dumb to again fetch the session with authClient.useSession(), of course i could use the session directly in the component but this session wont re-render on authClient.updateUser

So this would be perfect for cases where you want to only initially get a session on the server to redirect with that, and then take over with client side session management but avoiding an additional call to /get-session

Describe the solution you'd like

So basically when you load a session server sidely to then set the session data directly in the client auth instance with for example authClient.setSession(sessionData)

Describe alternatives you've considered

Right now you can just use the session data directly in the component but you must handle re rendering yourself for example if updateUser was successfull, so the authClient.useSession() hook would be completely useless or you could just request the session again on the client but this leads to an extended loading time because you could have just used the session data of the loaderData that the server already got and set it via my requested function authClient.setSession

Additional context

No response

Originally created by @GitonioDev on GitHub (Aug 22, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. When using a server side arch like remix and you want to server sidely check if a user is authenticated then you would use a loader with the server side getSession with headers and conditionally redirect based on the logged in status because you then already fetched the session it would dumb to again fetch the session with authClient.useSession(), of course i could use the session directly in the component but this session wont re-render on authClient.updateUser So this would be perfect for cases where you want to only initially get a session on the server to redirect with that, and then take over with client side session management but avoiding an additional call to /get-session ### Describe the solution you'd like So basically when you load a session server sidely to then set the session data directly in the client auth instance with for example authClient.setSession(sessionData) ### Describe alternatives you've considered Right now you can just use the session data directly in the component but you must handle re rendering yourself for example if updateUser was successfull, so the authClient.useSession() hook would be completely useless or you could just request the session again on the client but this leads to an extended loading time because you could have just used the session data of the loaderData that the server already got and set it via my requested function authClient.setSession ### Additional context _No response_
GiteaMirror added the enhancementremix labels 2026-03-13 09:01:14 -05:00
Author
Owner

@ping-maxwell commented on GitHub (Aug 22, 2025):

So essentially you want session data loaded from the server to have a way to be passed to the client, to prevent the client making an additional get-session call to fetch session data.

Although I'm not much of an expert in all front-end frameworks, I'm pretty sure that how frameworks handle passing data from server to client can differ, I don't think there is a consistent/standard way to do this that works on all FE frameworks.

Until we have UI part of Better-Auth (thus meaning individual support for each FE framework and it's code for UI components) I don't think it's possible support this out-of-the-box in an agnostic way as I've described earlier.

If I'm wrong any correction would be appreciated

@ping-maxwell commented on GitHub (Aug 22, 2025): So essentially you want session data loaded from the server to have a way to be passed to the client, to prevent the client making an additional get-session call to fetch session data. Although I'm not much of an expert in all front-end frameworks, I'm pretty sure that how frameworks handle passing data from server to client can differ, I don't think there is a consistent/standard way to do this that works on all FE frameworks. Until we have UI part of Better-Auth (thus meaning individual support for each FE framework and it's code for UI components) I don't think it's possible support this out-of-the-box in an agnostic way as I've described earlier. If I'm wrong any correction would be appreciated
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1755