Server Auth Not Working
I've followed the Convex Auth docs on how to set everything up and have also followed the Debugging Authentication docs. Everything seems to be working correctly to the end of step 3 (I have a valid JWT with "aud", "iss", and "sub" in the payload that matches my Convex site). However, calling the auth functions in my queries/mutations still return null (both in console logs and in the Convex Logs page).
Set Up Convex Auth - Convex Auth
Authentication library for your Convex backend
3 Replies
I think I discovered the issue. I was using the Tanstack Query integration and it was not passing the JWT to the backend. Switching from
useSuspenseQuery(convexQuery(api.users.getUser, {}))
to useQuery(api.users.getUser)
(from convex/react
allowed the server/backend to get the correct auth data.
However, I would really like to continue using Tanstack Query. Is there a way to continue using Tanstack Query but also have the authentication passed to the backend properly? I've followed the Convex Tanstack Query docs and can't seem to get it to work.Convex with TanStack Query | Convex Developer Hub
Integrate Convex with TanStack Query for advanced data fetching patterns
I finally got it working. I was incorrectly passing the Convex client to Tanstack Query client.
what was the right approach?