useActiveOrganization is returning null always
This does not work even if setting active organization id on the create and in manually in middleware also
30 Replies
helper function
i think there is issue with use hooks dont know why but
nether useSession nor any use hooks is working
@admin can someone help me with this am i doing something wrong ?
in your authClient you're passing some server plugins. nextCookies is a server only plugin
and passkeys is server too, you need to use passkeyClient()
you're also missing some plugins on the server auth instance, like
passkey needs to be in the server auth config's plugins list.
you're also missing twoFactor()yes backend i removed plugins before sharing to reduce message size but i am using them
this is server side
this is client side
still the issue persists
@Ping can you please help me ? its urgent
if you check ur db, does each session actually have an activeOrganizationId?
@Ping yes

and this is happening with all use hooks from better auth
can you show me how you're calling the hooks?
const { data: organization } = authClient.useActiveOrganization();
this way
I mean the environment it's at, such as within rsc or normal components.
whatever hook i use it is not working if it is useSession or useActiveOrganization or any
are you checking the isPending state?
In your code I noticed you're passing the organization to a commented out codeblock where you grab the team based on the org - but you need to check if
useActiveOrganization is pending first, since while it's pending the result is always nulli think no but is it not cached ?
it will still hit your server, the caching prevents it from hitting your DB. it still takes time to respond the result from the server
I recommend checking your dev tools in your browser to check the request and see it's results from there
ok let me check it and there is another issue don't know it that is the issue
when i use
use hook from react for authClient promis functions like getSession then it is infinite
can you clarify? I don't understand your question
when i do this the api cals done is infinite

@Ping
this should work right for atleast logging ? even then it is not working
Check your network tab in dev tools, what does that show?
when i use hooks there is api call done
{
"name": "Testing",
"slug": "testing",
"logo": null,
"createdAt": "2025-09-23T04:56:20.405Z",
"metadata": null,
"id": "gtdauEtdizzbc09NpkAzTyM7o4rnYlnW",
"invitations": [],
"members": [
{
"organizationId": "gtdauEtdizzbc09NpkAzTyM7o4rnYlnW",
"userId": "R9o0j3Nx9tWyWhJkrZR0OTqhKuvWnWZU",
"role": "owner",
"createdAt": "2025-09-23T04:56:21.527Z",
"id": "WGM0IcoiQOfYJyQd7HiqX78VRkz76Kqs",
"user": {
"id": "R9o0j3Nx9tWyWhJkrZR0OTqhKuvWnWZU",
"name": "Engineer Boy",
"email": "engineerboy.ran@gmail.com",
"image": "https://lh3.googleusercontent.com/a/ACg8ocIfABbnoYxPH7tPLh9kyu42SXdLi2mZVkKWf-eVATnE2OYGAgM=s96-c"
}
}
],
"teams": [
{
"name": "Testing",
"organizationId": "gtdauEtdizzbc09NpkAzTyM7o4rnYlnW",
"createdAt": "2025-09-23T04:56:22.058Z",
"updatedAt": "2025-09-23T04:56:22.060Z",
"id": "0Z9PPwQXl1uNGCpVdrxl5B397cNwEv0n"
}
]
}
and also responde but the hook in the code return null
try to modify your useEffect to add
isPending logs, and update the dependency array too
also add error in case something popped upthis is printed

only three logs and pending is never gets false and data is not returned
it could be possible that there are other authClient requests that are on-going causing it to triggering these.
Try making a test page in your nextjs app and specifically run this useEffect hook to test
i did not get it
Just to test - please make a new page.tsx and test and see if you run into the same issue on a fresh page
^^ and add the useEffect of course