INFINITE loading state
I'm working on a project and I got stuck into an infinite loading state where the promise is never resolved. I went to the convex dashboard to run the function and worked, but here simply doesn't return anything. I don't have errors anywhere


33 Replies
@pulgueta_ share your code please
in your logs, the promise attribute says you have an error
"experimental_prefetch"
https://github.com/pulgueta/panabarbero/blob/pulgueta/convex/apps/web/src/hooks/use-barbershop.ts
this was working well, it was in between the better-auth thing I had in other issues when I started experiencing this. That experimental_prefetchOnRender flag didn't do the job, enabled and disabled - still got the error
GitHub
panabarbero/apps/web/src/hooks/use-barbershop.ts at pulgueta/convex...
PanaBarbero monorepo. React Native with Expo + Hono backend managed with Turborepo. - pulgueta/panabarbero
GitHub
panabarbero/apps/web/src/components/barbershops/barbershop-grid.tsx...
PanaBarbero monorepo. React Native with Expo + Hono backend managed with Turborepo. - pulgueta/panabarbero
hmm im not 100% sure, perhaps it has something to do with the betterauth integration if that's when it popped up, I havent done that myself
Promise usually resolves MINUTES after getting in and out of the browser on mobile, and all this being already deployed
update: resolved quickly for some time and navigating through another page crashed. Went to my pc to test on another device and still showed loading forever
Do you have
expectAuth: true on your convex clientI do

removing the experimental flag doesn't fix the bug
Try turning off expectAuth, that's likely why it's loading infinitely - it's waiting for the user to be authenticated
expectAuth is itself experimental, helpful if your app can work with all convex function calls on hold until auth resolves
alright I think that worked. But still can't get sessions from the client nor from an authenticated call. Every time it throws an error because is "unauthenticated", I want to get the current user from the session on the server


If you have a Convex function that throws an error if the user is not authenticated, you have to wait until Convex is authenticated on the client before calling the function. You can use the Authenticated/Unauthenticated/AuthLoading components or the useConvexAuth hook to get auth state in the client.
That still doesn't give me the user information I need. useConvexAuth only returns 2 booleans and I need the user_id for what I do. The functions throw errors on what the docs say is the usage
I'm not expecting it to throw an error because I only want to know if there's a current user, I've set specific error throws for the mutations/queries that can't be accessed directly. Isn't there a simple way to use the useSession from better-auth? How else can we handle client-side auth?
You want
authComponent.safeGetAuthUser()Great, thanks! Almost there! I just keep getting this error from the first image where cannot found the endpoints to update my session. Although the session is created in convex (I can see it created in the dashboard) it doesn't appear to be existing when I call the useSession hook I just made with that method. I've registered the http routes with the authComponent
Even the convex (un)authenticated components always show unauthenticated
Oh I didn't even notice the 404s, do you see those in the Convex dashboard too?
I just tried to login and got these

Can you search your codebase for
update-session, that endpoint you're calling doesn't exist in Better Auth

I don't have anything that relates to update-session, tried looking for it in convex and nothing
Not even using the better-auth's hook, I'm using the one I made with the safeGetAuthUser
I'm saying to grep your codebase for it

This is what I'm referencing, those 404's are correct
Nothing comes up, have nothing with update-session
Follow the trace to see why an update-session endpoint is being called I guess
I searched against git history in better-auth and the component, neither have contained that string
what version of better-auth?
Just looking at that log main.tsx:45 should have some answers
Here it is

"@better-auth/expo": "1.3.27",
"better-auth": "1.3.27"
If you hit the arrow in the log it should expand and provide a proper trace to show where the actual source is.


Yeah you'll have to do a bit of standard debugging to figure out the source of that call, all I know is there's no
update-session in better auth or the component code.Turns out I didn't have the crossDomainClient plugin on my better-auth client instance
What a pain in the ass
What framework are you using?
oh that's tanstack
you don't need cross domain with tanstack
and that still doesn't clarify the update-session calls, curious if those are still happening
It's a vite spa with tstack router
Didn't set the crossDomainClient and that missing plugin was causing the issue where I couldn't get a session
I mean, I got one but on the second call (update-session) it was removed or something like that, I could see the network tab response with the session data but the next one deleted/removed it from the final response the hook logged
Ah okay - yeah if you're doing a spa, the React guide in the docs is more what you want to follow, tanstack guide assumes fullstack