Give better-auth the session in the root layout, so that the client page hydrates with the existing session #1193

Closed
opened 2026-03-13 08:27:30 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @DavidIlie on GitHub (May 11, 2025).

Originally assigned to: @Kinfe123 on GitHub.

The title says it all,

Is that possible? Is that already implemented in better-auth?

Because for me in NextAuth/Authjs I can by default in the context can wrap the session that I fetch on the server, and it makes everything seem smooth and fast.

Thank you

Originally created by @DavidIlie on GitHub (May 11, 2025). Originally assigned to: @Kinfe123 on GitHub. The title says it all, Is that possible? Is that already implemented in better-auth? Because for me in NextAuth/Authjs I can by default in the context can wrap the session that I fetch on the server, and it makes everything seem smooth and fast. Thank you
GiteaMirror added the enhancement label 2026-03-13 08:27:30 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 7, 2025):

Hi, @DavidIlie. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You asked if better-auth supports passing session data in the root layout for client pages to hydrate with the existing session.
  • Your goal is to achieve smoother and faster rendering similar to NextAuth/Authjs.
  • There have been no comments or updates on this issue so far.
  • The feature status remains unresolved and no official guidance has been provided yet.

Next Steps:

  • Please let me know if this issue is still relevant with the latest version of better-auth by commenting here.
  • If I don’t hear back within 7 days, this issue will be automatically closed.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Sep 7, 2025): Hi, @DavidIlie. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You asked if better-auth supports passing session data in the root layout for client pages to hydrate with the existing session. - Your goal is to achieve smoother and faster rendering similar to NextAuth/Authjs. - There have been no comments or updates on this issue so far. - The feature status remains unresolved and no official guidance has been provided yet. **Next Steps:** - Please let me know if this issue is still relevant with the latest version of better-auth by commenting here. - If I don’t hear back within 7 days, this issue will be automatically closed. Thank you for your understanding and contribution!
Author
Owner

@ping-maxwell commented on GitHub (Oct 2, 2025):

Does auth.api.getSession not work for you case?

@ping-maxwell commented on GitHub (Oct 2, 2025): Does `auth.api.getSession` not work for you case?
Author
Owner

@DavidIlie commented on GitHub (Oct 11, 2025):

I assume so, but in devtools it queries the API endpoint every single time. Whereas, with next-auth, I hydrate on the server, and it is part of a react context that queries or hydrates from the server, and refetches on window focus.

I assume developers need to create their own wrapper around this to have this feature?

@DavidIlie commented on GitHub (Oct 11, 2025): I assume so, but in devtools it queries the API endpoint **every** single time. Whereas, with next-auth, I hydrate on the server, and it is part of a react context that queries or hydrates from the server, and refetches on window focus. I assume developers need to create their own wrapper around this to have this feature?
Author
Owner

@dosubot[bot] commented on GitHub (Jan 10, 2026):

Hi, @DavidIlie. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You asked if better-auth can provide session data in the root layout for client pages to hydrate with an existing session, similar to NextAuth/Authjs.
  • The discussion noted that using auth.api.getSession queries the API on every request, which differs from NextAuth's server hydration and React context method.
  • It was suggested that a custom wrapper might be necessary to achieve the desired behavior.
  • No implementation or resolution has been made on this feature request.
  • The issue has had no recent updates.

Next Steps:

  • Please let me know if this feature is still relevant to the latest version of better-auth by commenting on this issue.
  • If I do not hear back within 7 days, this issue will be automatically closed.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Jan 10, 2026): Hi, @DavidIlie. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You asked if better-auth can provide session data in the root layout for client pages to hydrate with an existing session, similar to NextAuth/Authjs. - The discussion noted that using `auth.api.getSession` queries the API on every request, which differs from NextAuth's server hydration and React context method. - It was suggested that a custom wrapper might be necessary to achieve the desired behavior. - No implementation or resolution has been made on this feature request. - The issue has had no recent updates. **Next Steps:** - Please let me know if this feature is still relevant to the latest version of better-auth by commenting on this issue. - If I do not hear back within 7 days, this issue will be automatically closed. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1193