pulgueta_
pulgueta_3w ago

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
No description
No description
33 Replies
Kenny
Kenny3w ago
@pulgueta_ share your code please in your logs, the promise attribute says you have an error "experimental_prefetch"
pulgueta_
pulgueta_OP3w ago
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
Kenny
Kenny3w ago
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
pulgueta_
pulgueta_OP3w ago
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
erquhart
erquhart3w ago
Do you have expectAuth: true on your convex client
pulgueta_
pulgueta_OP3w ago
I do
No description
pulgueta_
pulgueta_OP3w ago
removing the experimental flag doesn't fix the bug
erquhart
erquhart3w ago
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
pulgueta_
pulgueta_OP3w ago
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
No description
No description
erquhart
erquhart3w ago
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.
pulgueta_
pulgueta_OP3w ago
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
// You can get the current user from the auth component
export const getCurrentUser = query({
args: {},
handler: async (ctx) => {
return await authComponent.getAuthUser(ctx);
},
});
// You can get the current user from the auth component
export const getCurrentUser = query({
args: {},
handler: async (ctx) => {
return await authComponent.getAuthUser(ctx);
},
});
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?
erquhart
erquhart3w ago
You want authComponent.safeGetAuthUser()
pulgueta_
pulgueta_OP3w ago
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
erquhart
erquhart3w ago
Oh I didn't even notice the 404s, do you see those in the Convex dashboard too?
pulgueta_
pulgueta_OP3w ago
I just tried to login and got these
No description
erquhart
erquhart3w ago
Can you search your codebase for update-session, that endpoint you're calling doesn't exist in Better Auth
pulgueta_
pulgueta_OP3w ago
No description
No description
pulgueta_
pulgueta_OP3w ago
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
erquhart
erquhart3w ago
I'm saying to grep your codebase for it
erquhart
erquhart3w ago
No description
erquhart
erquhart3w ago
This is what I'm referencing, those 404's are correct
pulgueta_
pulgueta_OP3w ago
Nothing comes up, have nothing with update-session
erquhart
erquhart3w ago
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
pulgueta_
pulgueta_OP3w ago
Here it is
No description
pulgueta_
pulgueta_OP3w ago
"@better-auth/expo": "1.3.27", "better-auth": "1.3.27"
erquhart
erquhart3w ago
If you hit the arrow in the log it should expand and provide a proper trace to show where the actual source is.
pulgueta_
pulgueta_OP3w ago
No description
No description
erquhart
erquhart3w ago
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.
pulgueta_
pulgueta_OP3w ago
Turns out I didn't have the crossDomainClient plugin on my better-auth client instance What a pain in the ass
erquhart
erquhart3w ago
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
pulgueta_
pulgueta_OP3w ago
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
erquhart
erquhart3w ago
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

Did you find this page helpful?