prometheas πŸ”₯P
Convex Communityβ€’2y agoβ€’
13 replies
prometheas πŸ”₯

Trouble using useQuery and convexQuery with queries that use ctx.auth.getUserIdentity()

So, like it says on the tin β€” I am unable to use the standard
useQuery()
(from
convex/react
) or the
@convex-dev/react-query
package's
convexQuery()
functions to call
query()
functions in my Convex API that check
ctx.auth.getUserIdentity()
as an auth guard mechanism.

In other places in my nextjs project (server actions), I can invoke such query functions by adding a third argument with an auth token, like this:

import { auth } from '@clerk/nextjs/server';
import { fetchQuery } from 'convex/nextjs';

const token = (await auth().getToken({ template: 'convex' })) ?? null

const someResult = await fetchQuery(
  api.messages.getLatest,
  { limit: 30 },
  { token }       // <------ clerk auth token
);


Am I using the wrong approach for auth guarding the query funciton? Or is there some different mechanism for passing a token to the
useQuery()
and
convexQuery()
functions?
Was this page helpful?