getUserIdentity() returning null
Hey all, I'm building an app and I've come across an issue where I have a currentUser function that uses the standard ctx.auth.getUserIdentity() method, but it seems to be returning null despite being logged in. I'm successfully using the function in another function with no issues. This is called as a query on the frontend. Code:
console.log there to confirm it's null.

6 Replies
Welcome!
I haven't run into this, but I can try and help troubleshoot. Have you tried calling this query from the same place you're calling the other query?
I've changed how I was pulling in the data. the identity doesn't seem to be initially loaded (which makes sense in hindsight).
For others that have this question, the solution was to account for that in the frontend by handling a null user and showing a loading overlay until it's all there.
@Elfinslayer one note is some folks find the
skip
capability of useQuery
useful here: https://docs.convex.dev/client/react#skipping-queriesConvex React | Convex Developer Hub
Convex React is the client library enabling your React application to interact
that way you can do something like:
if "skip" is passed instead of arguments to useQuery the server won't be called
oof, i had used that in another project and totally forgot about it. thanks!
(if you follow Jamie's suggestion, use
useConvexAuth
or Authenticated
from convex/react
, as they wait not just for the auth provider but also for your Convex backend to receive the auth)