[GH-ISSUE #2051] Server-side session prefetch #9027

Closed
opened 2026-04-13 04:18:04 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @juliuslipp on GitHub (Mar 29, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/2051

Is this suited for github?

  • Yes, this is suited for github

No response

Describe the solution you'd like

Would be amazing if there would be a simple way to populate the session from the server, so it's immediately available in the useSession hook :)

Describe alternatives you've considered

Fetching it twice :(

Additional context

No response

Originally created by @juliuslipp on GitHub (Mar 29, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/2051 ### Is this suited for github? - [ ] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. _No response_ ### Describe the solution you'd like Would be amazing if there would be a simple way to populate the session from the server, so it's immediately available in the useSession hook :) ### Describe alternatives you've considered Fetching it twice :( ### Additional context _No response_
GiteaMirror added the locked label 2026-04-13 04:18:04 -05:00
Author
Owner

@hbmartin commented on GitHub (Mar 29, 2025):

You can already prepopulate session info from the SSR methods. Or you can store the session in a cookie https://www.better-auth.com/docs/concepts/session-management#cookie-cache

<!-- gh-comment-id:2763852066 --> @hbmartin commented on GitHub (Mar 29, 2025): You can already prepopulate session info from the SSR methods. Or you can store the session in a cookie https://www.better-auth.com/docs/concepts/session-management#cookie-cache
Author
Owner

@kinglouie commented on GitHub (Apr 11, 2025):

@hbmartin in the link you provided, I cant find the part on how to prepopulate the session info from the server.
Maybe you could share an example?
I use getSession on the server of my sveltekit app to restrict access to certain roles. Now I want to pass down the session info to my components so they can display session data but ideally without doing another fetch to the server to validate the the session cookie again.

<!-- gh-comment-id:2795939439 --> @kinglouie commented on GitHub (Apr 11, 2025): @hbmartin in the link you provided, I cant find the part on how to prepopulate the session info from the server. Maybe you could share an example? I use getSession on the server of my sveltekit app to restrict access to certain roles. Now I want to pass down the session info to my components so they can display session data but ideally without doing another fetch to the server to validate the the session cookie again.
Author
Owner

@jamiter commented on GitHub (Feb 23, 2026):

This doesn't seem to be solved yet. See also https://github.com/better-auth/better-auth/issues/4319

I've added our workaround to that ticket, so others might benefit. Hopefully a build-in solution will follow.

<!-- gh-comment-id:3947229480 --> @jamiter commented on GitHub (Feb 23, 2026): This doesn't seem to be solved yet. See also https://github.com/better-auth/better-auth/issues/4319 I've added our workaround to that ticket, so others might benefit. Hopefully a build-in solution will follow.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#9027