Document useSession behavior for session expiration #932

Closed
opened 2026-03-13 08:10:26 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @lukasb on GitHub (Mar 27, 2025).

Is this suited for github?

  • Yes, this is suited for github

useSession doesn't trigger a state change when a session expires. That's apparently intended behavior: https://discord.com/channels/1288403910284935179/1353810672458403920/1353820038154551469

However it's not obvious to someone getting started with better-auth

Describe the solution you'd like

Describe when useSession will and will not fire here: https://www.better-auth.com/docs/concepts/session-management#use-session

Describe alternatives you've considered

Even better would be to have the useSession hook have a timeout like in this version: 5424706d8c/src/hooks/session/use-session.ts (L45)

And then fire if the session expires

Additional context

No response

Originally created by @lukasb on GitHub (Mar 27, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. useSession doesn't trigger a state change when a session expires. That's apparently intended behavior: https://discord.com/channels/1288403910284935179/1353810672458403920/1353820038154551469 However it's not obvious to someone getting started with better-auth ### Describe the solution you'd like Describe when useSession will and will not fire here: https://www.better-auth.com/docs/concepts/session-management#use-session ### Describe alternatives you've considered Even better would be to have the useSession hook have a timeout like in this version: https://github.com/daveyplate/better-auth-tanstack/blob/5424706d8cfb914cc8f0b16053e7b330efbdbb4a/src/hooks/session/use-session.ts#L45 And then fire if the session expires ### Additional context _No response_
Author
Owner

@dosubot[bot] commented on GitHub (Jun 26, 2025):

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

Issue Summary:

  • You raised a concern about the useSession hook not triggering a state change upon session expiration.
  • Suggested updating documentation to clarify when useSession triggers.
  • Proposed implementing a timeout mechanism within the hook for better session management.
  • No further comments or activity have been made on this issue.

Next Steps:

  • Please let me know if this issue is still relevant to the latest version of the better-auth repository by commenting here.
  • If no updates are provided, the issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Jun 26, 2025): Hi, @lukasb. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale. **Issue Summary:** - You raised a concern about the `useSession` hook not triggering a state change upon session expiration. - Suggested updating documentation to clarify when `useSession` triggers. - Proposed implementing a timeout mechanism within the hook for better session management. - No further comments or activity have been made on this issue. **Next Steps:** - Please let me know if this issue is still relevant to the latest version of the better-auth repository by commenting here. - If no updates are provided, the issue will be automatically closed in 7 days. Thank you for your understanding and contribution!
Author
Owner

@lukasb commented on GitHub (Jun 26, 2025):

Yes, this is still relevant.

On Thu, Jun 26, 2025 at 09:03 dosubot[bot] @.***> wrote:

dosubot[bot] left a comment (better-auth/better-auth#2032)
https://github.com/better-auth/better-auth/issues/2032#issuecomment-3008996755

Hi, @lukasb https://github.com/lukasb. I'm Dosu https://dosu.dev, and
I'm helping the better-auth team manage their backlog. I'm marking this
issue as stale.

Issue Summary:

  • You raised a concern about the useSession hook not triggering a
    state change upon session expiration.
  • Suggested updating documentation to clarify when useSession triggers.
  • Proposed implementing a timeout mechanism within the hook for better
    session management.
  • No further comments or activity have been made on this issue.

Next Steps:

  • Please let me know if this issue is still relevant to the latest
    version of the better-auth repository by commenting here.
  • If no updates are provided, the issue will be automatically closed
    in 7 days.

Thank you for your understanding and contribution!


Reply to this email directly, view it on GitHub
https://github.com/better-auth/better-auth/issues/2032#issuecomment-3008996755,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAD4EKNMFQOQNNG2GXLNIDT3FQKVVAVCNFSM6AAAAABZ6FNGOCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTAMBYHE4TMNZVGU
.
You are receiving this because you were mentioned.Message ID:
@.***>

@lukasb commented on GitHub (Jun 26, 2025): Yes, this is still relevant. On Thu, Jun 26, 2025 at 09:03 dosubot[bot] ***@***.***> wrote: > *dosubot[bot]* left a comment (better-auth/better-auth#2032) > <https://github.com/better-auth/better-auth/issues/2032#issuecomment-3008996755> > > Hi, @lukasb <https://github.com/lukasb>. I'm Dosu <https://dosu.dev>, and > I'm helping the better-auth team manage their backlog. I'm marking this > issue as stale. > > *Issue Summary:* > > - You raised a concern about the useSession hook not triggering a > state change upon session expiration. > - Suggested updating documentation to clarify when useSession triggers. > - Proposed implementing a timeout mechanism within the hook for better > session management. > - No further comments or activity have been made on this issue. > > *Next Steps:* > > - Please let me know if this issue is still relevant to the latest > version of the better-auth repository by commenting here. > - If no updates are provided, the issue will be automatically closed > in 7 days. > > Thank you for your understanding and contribution! > > — > Reply to this email directly, view it on GitHub > <https://github.com/better-auth/better-auth/issues/2032#issuecomment-3008996755>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/AAD4EKNMFQOQNNG2GXLNIDT3FQKVVAVCNFSM6AAAAABZ6FNGOCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTAMBYHE4TMNZVGU> > . > You are receiving this because you were mentioned.Message ID: > ***@***.***> >
Author
Owner

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

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

Issue Summary:

  • You raised a concern about the useSession hook's behavior not triggering state changes when a session expires, which can be confusing.
  • You suggested improving the documentation to clarify when useSession fires.
  • You also proposed adding a timeout feature to better handle session expiration updates.
  • The issue was marked as stale due to inactivity, but you confirmed it is still relevant.
  • Maintainers have acknowledged your confirmation with positive reactions.

Next Steps:

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

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Sep 25, 2025): Hi, @lukasb. 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 raised a concern about the useSession hook's behavior not triggering state changes when a session expires, which can be confusing. - You suggested improving the documentation to clarify when useSession fires. - You also proposed adding a timeout feature to better handle session expiration updates. - The issue was marked as stale due to inactivity, but you confirmed it is still relevant. - Maintainers have acknowledged your confirmation with positive reactions. **Next Steps:** - Please let me know if this issue is still relevant with the latest version of better-auth by commenting here. - If I do not hear back within 7 days, the 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#932