MAXXtreme
MAXXtreme2w ago

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).
// auth.ts
export const getAuth = query({
args: {},
handler: async (ctx) => {
const userId = await getAuthUserId(ctx)
const user = await ctx.auth.getUserIdentity()
console.log('Auth', userId, user) // 'Auth', null, null
return { userId, user }
},
})
// auth.ts
export const getAuth = query({
args: {},
handler: async (ctx) => {
const userId = await getAuthUserId(ctx)
const user = await ctx.auth.getUserIdentity()
console.log('Auth', userId, user) // 'Auth', null, null
return { userId, user }
},
})
// auth.config.ts
export default {
providers: [
{
domain: process.env.VITE_CONVEX_SITE_URL,
applicationID: 'convex',
},
],
}
// auth.config.ts
export default {
providers: [
{
domain: process.env.VITE_CONVEX_SITE_URL,
applicationID: 'convex',
},
],
}
Set Up Convex Auth - Convex Auth
Authentication library for your Convex backend
3 Replies
MAXXtreme
MAXXtremeOP2w ago
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
MAXXtreme
MAXXtremeOP2w ago
I finally got it working. I was incorrectly passing the Convex client to Tanstack Query client.
David Ojo
David Ojo2d ago
what was the right approach?

Did you find this page helpful?