useListOrganizations does not wait for auth state to settle #1133

Closed
opened 2026-03-13 08:24:19 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @widavies on GitHub (Apr 30, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

I'm using the organizations plugin. I've noticed that the useListOrganizations hook does not wait for the auth session state to settle - it will intermittently succeed with a 200 or fail with 401 because of this.

  1. Call authClient.useListOrganizations at the beginning of a client component
  2. The server will sometimes forbid the request with a 401

The first request fails, then the auth state settles, then the hook retries with a success:
Image

Current vs. Expected behavior

  • Expect no 401

What version of Better Auth are you using?

1.2.7

Provide environment information

- Windows 11, Chrome, Next.JS

Which area(s) are affected? (Select all that apply)

Backend, Client

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

Using organizations plugin

Originally created by @widavies on GitHub (Apr 30, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce I'm using the organizations plugin. I've noticed that the `useListOrganizations` hook does not wait for the auth session state to settle - it will intermittently succeed with a `200` or fail with `401` because of this. 1. Call `authClient.useListOrganizations` at the beginning of a client component 2. The server will sometimes forbid the request with a 401 The first request fails, then the auth state settles, then the hook retries with a success: ![Image](https://github.com/user-attachments/assets/505ecebc-8a5e-4e20-b412-dd56af081f47) ### Current vs. Expected behavior - Expect no 401 ### What version of Better Auth are you using? 1.2.7 ### Provide environment information ```bash - Windows 11, Chrome, Next.JS ``` ### Which area(s) are affected? (Select all that apply) Backend, Client ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context Using organizations plugin
Author
Owner

@widavies commented on GitHub (Apr 30, 2025):

Nevermind - this was caused by an issue with a hook running in SSR mode, thanks!

@widavies commented on GitHub (Apr 30, 2025): Nevermind - this was caused by an issue with a hook running in SSR mode, thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1133