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:
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?11 Replies
token will automatically go to the server...on the server you can do simple check...
Thanks for taking the time to attempt an assist, @jamalsoueidan π β¦
So,
getAuthUserId(ctx)
doesn't seem to be available in any package I'm using β to confirm, is that simply intended to be a generic name for a project-defined Convex function? The specific Convex API function I'm attempting unsuccessfully to use is ctx.auth.getUserIdentity()
and finding β when invoked from client code β that it's returning null
.
And, in case it may be something I hadn't made clear enough, and may account for a difference in outcomes, I'm using Clerk authβ¦
Given that you seem to believe that identity details ought to be figured out automatically, and the fact that NONE of Convex's React docs show explicit token passing, I'm starting to wonder if perhaps it's worth double-checking how my project's convex provider is configured in tandem with Clerk, as that bit was implemented by a developer no longer on the team.import { convexAuth, getAuthUserId } from "@convex-dev/auth/server";
frst of all: YOU, @jamalsoueidan, are a champion community helper βΒ i super appreciate you!
Did you make it work?
i had a look at the way convex and clerk were integrated⦠and it looked NOTHING like the examples
you need a provider for the authentication on the frontend
i have blown it all away and replaced it with what the Convex docs show, and β so far, so good β but i've got a bunch of testing around the rest of the app to ensure i haven't broken anything (sadly, our automated tests are lighter than I'd have preferred)
yes, i know⦠but there was all sorts of insanse stuff going on there
im using convex auth very simple, 3 linies..
const [convex] = useState(() => new ConvexReactClient(ENV.CONVEX_URL));
<ConvexAuthProvider client={convex}>
{children}
</ConvexAuthProvider>
i would explain, but I think my attempting to do so would make anyone else dumber for having tried to read and understand that weirdness lol
i do appreciate your assist, though, very much. i'll confirm in a bit on the outcomes
yes good, i hope you get it to work.... usually on any project i start with auth π