useSession not working properly #240

Closed
opened 2026-03-13 07:39:17 -05:00 by GiteaMirror · 7 comments
Owner

Originally created by @ayushsharma82 on GitHub (Nov 17, 2024).

Describe the bug
I'm using useSession hook of better-auth in my nextjs project and it's not working properly in sense that - sometimes the isPending property is left as true and never switches to false once get-session request is completed.

I think this is the most critical part of the app, I'm using useSession to protect routes, show loader and do other things. With this current bug, my loader keeps spinning and the user is stuck forever at that loading animation.

To Reproduce
Steps to reproduce the behavior:

  1. Sign in with email and password auth
  2. Signout via authClient.signOut();
  3. Refresh page
  4. The useSession hook should break at this step and isPending variable would be stuck at true.

In the network monitor, I can see better-auth client SDK make the request to my backend and the response was received as well. But the client SDK fails to update the isPending, data and error fields.

Expected behavior
The useSession hook should never miss these get-session API responses or be stuck at isPending = true forever.

Desktop (please complete the following information):

  • OS: macOS 15.1
  • Browser: Safari
  • Better-Auth Version: 0.8.4
Originally created by @ayushsharma82 on GitHub (Nov 17, 2024). **Describe the bug** I'm using `useSession` hook of better-auth in my nextjs project and it's not working properly in sense that - sometimes the `isPending` property is left as `true` and never switches to `false` once get-session request is completed. I think this is the most critical part of the app, I'm using useSession to protect routes, show loader and do other things. With this current bug, my loader keeps spinning and the user is stuck forever at that loading animation. **To Reproduce** Steps to reproduce the behavior: 1. Sign in with email and password auth 2. Signout via `authClient.signOut();` 3. Refresh page 4. The `useSession` hook should break at this step and `isPending` variable would be stuck at `true`. In the network monitor, I can see better-auth client SDK make the request to my backend and the response was received as well. But the client SDK fails to update the `isPending`, `data` and `error` fields. **Expected behavior** The `useSession` hook should never miss these `get-session` API responses or be stuck at `isPending` = `true` forever. **Desktop (please complete the following information):** - OS: macOS 15.1 - Browser: Safari - Better-Auth Version: 0.8.4
Author
Owner

@ayushsharma82 commented on GitHub (Nov 17, 2024):

More observation: It breaks 60% of the time after signout and works 40% of the time with isPending set to false shortly after receiving response from API.

@ayushsharma82 commented on GitHub (Nov 17, 2024): More observation: It breaks 60% of the time after signout and works 40% of the time with `isPending` set to `false` shortly after receiving response from API.
Author
Owner

@ayushsharma82 commented on GitHub (Nov 17, 2024):

Another great observation: This bug happens on Safari so far. I've tested with Chrome and the client SDK behaves properly in that case every single time.

@ayushsharma82 commented on GitHub (Nov 17, 2024): Another great observation: This bug happens on Safari so far. I've tested with Chrome and the client SDK behaves properly in that case every single time.
Author
Owner

@Bekacru commented on GitHub (Nov 18, 2024):

As you can see here, the pending value should reset on success or error. Could you verify if the request resolves properly or hangs on the response? Also, please update it to version 0.8.6 to make sure everything is up-to-date.

@Bekacru commented on GitHub (Nov 18, 2024): As you can see [here](https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/client/query.ts#L46-L74), the `pending` value should reset on success or error. Could you verify if the request resolves properly or hangs on the response? Also, please update it to version 0.8.6 to make sure everything is up-to-date.
Author
Owner

@ayushsharma82 commented on GitHub (Nov 19, 2024):

@Bekacru I see but still the same thing. Something breaks in Safari, I checked network analyzer and XHR request is receiving valid response (200, null response, same as Chrome).

PS: Tried with 0.8.8-beta.2

@ayushsharma82 commented on GitHub (Nov 19, 2024): @Bekacru I see but still the same thing. Something breaks in Safari, I checked network analyzer and XHR request is receiving valid response (200, null response, same as Chrome). PS: Tried with `0.8.8-beta.2`
Author
Owner

@ayushsharma82 commented on GitHub (Nov 20, 2024):

Solved. It was an issue within my own component.

@ayushsharma82 commented on GitHub (Nov 20, 2024): Solved. It was an issue within my own component.
Author
Owner

@ruaanetwork commented on GitHub (Feb 6, 2025):

Solved. It was an issue within my own component.

can you please share what was the issue because i am having the same issue.
using react typescript vite project

@ruaanetwork commented on GitHub (Feb 6, 2025): > Solved. It was an issue within my own component. can you please share what was the issue because i am having the same issue. using react typescript vite project
Author
Owner

@joseph-9900 commented on GitHub (Feb 25, 2025):

Solved. It was an issue within my own component.

Hey @ayushsharma82 I am facing the same issue, can you please explain how did you solve?

@joseph-9900 commented on GitHub (Feb 25, 2025): > Solved. It was an issue within my own component. Hey @ayushsharma82 I am facing the same issue, can you please explain how did you solve?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#240