Endpoints being called 2000+ times on refresh

It's very inconsistent when it happens, but sometimes it will make ~2000 requests. Relevant code:
// dashboard-sidebar.tsx
const { data: organizations } = authClient.useListOrganizations();
const { data: activeOrganization } = authClient.useActiveOrganization();

// agency-selector.tsx
const { data: session } = authClient.useSession();
// dashboard-sidebar.tsx
const { data: organizations } = authClient.useListOrganizations();
const { data: activeOrganization } = authClient.useActiveOrganization();

// agency-selector.tsx
const { data: session } = authClient.useSession();
It's causing tremendous performance problems, and I'm unsure why it even happens in the first place.
No description
No description
5 Replies
HotShot
HotShotOP2mo ago
bump. i use better auth in multiple projects and they all seem to have this issue totally unreproducible, happens randomly. is better auth just broken? hello :(
sebastian
sebastian2mo ago
i would say there could be some re-render problem in those components, probably not related to the better-auth itself, perhaps some useeffect loop
HotShot
HotShotOP2mo ago
its happening in 2 of my apps both do not have any useEffect
HotShot
HotShotOP2mo ago
@bekacru sorry for tagging, but could the issue potentially be with the authclient useListOrganizations/useSession hook implementations? after dealing with this for months, the only documentation I could really find on the topic was this saying "if you prefer not to use the hook...", when the fix for this was to use tanstack query and make my own useSession/useListOrganizations hook implementation. i believe there is a flaw in the react hooks for the auth client
Basic Usage | Better Auth
Getting started with Better Auth
bekacru
bekacru2mo ago
Hey sorry for getting back to this late Is there anyway you can provide a reproduction I can take a look?

Did you find this page helpful?