ctx.auth.getUserIdentity() is returning undefined
Hey! Just started using Convex so far it's been amazing. I added the Clerk integration and I am also using the latest NextJS version(with app router). I created a query function that is getting some a list from the database. When I call it from the frontend it seems the backend doesn't have the user identity right away.
In this function I need to be able to get lists by the user id but the user is never defined. I have made sure I am logged in too. I have also made sure that I setup my auth.config.js correctly. It seems the mutation function works just fine but the queries do not. Any help would be awesome! Thanks. Here is what the logs look like. Seems like on load it's undefined and then eventually the data comes.
In this function I need to be able to get lists by the user id but the user is never defined. I have made sure I am logged in too. I have also made sure that I setup my auth.config.js correctly. It seems the mutation function works just fine but the queries do not. Any help would be awesome! Thanks. Here is what the logs look like. Seems like on load it's undefined and then eventually the data comes.

6 Replies
Hey @For Sparta, the client needs to authenticate with the Convex server, before it does UserIdentity is indeed undefined.
You can wrap your component in
Authenticated
to make sure it doesn't render until the client-server authentication handshake:
https://docs.convex.dev/auth/clerk#logged-in-and-logged-out-views
Alternatively you can return null
while the auth context is loading, and handle it on the client (this is slightly faster, as it avoids an additional roundtrip).Convex Clerk | Convex Developer Hub
Clerk is an authentication platform providing login via
Ahh yep that did it. Thank you.
Did the trick!
hi, This doesn't work for me in the backend as I try to get the user identity in a webhook function, but it keeps returning null
Here is what I get whenever I'm trying to get the user identity in a webhook

Here is the code:
export const webhookHandler = httpAction(async (ctx, request) => {
const body = await request.json();
const { target, installation } = body;
const userId = await getUserId(ctx);
if (userId === undefined) {
throw new ConvexError('User must be logged in.');
}
switch (target) {
case 'created':
await handleInstallationCreated(ctx, installation);
}
return new Response(
Webhook Recieved
, {
status: 200
});
});@The Cyberverse yours is a different issue, I gave a reply for it here: https://discord.com/channels/1019350475847499849/1218192747882872943/1218193536323817490