lldan
lldan14mo ago

getUserIdentity returning null, when you refresh the page

I am using Clerk to authorise users. I use the ctx.auth.getUserIdentity() method to get the user information. Everything is going fine until I decide to refresh the page. If I refresh the page, ctx.auth.getUserIdentity() returns null even though the user is definitely authorised.
5 Replies
lldan
lldanOP14mo ago
I read this thread, but I didn't understand how they solved this problem there
Michal Srb
Michal Srb14mo ago
Looks like a race. You have to wait for the server to receive the client authentication. You can do this by wrapping your component in Authenticated from convex/react (or by using useConvexAuth manually)
nicooo
nicooo14mo ago
Same here when I re render it shows me current logged in user, if I refresh it shows undefined. I don't know what's wrong. I used useConvexAuth and it returns false when page is refreshed. I am also using the useUser hook by clerk..
Michal Srb
Michal Srb13mo ago
Yeah, useConvexAuth will always show false first. But if you have the auth set up correctly, it should then switch to true after the auth provider fetches the token.

Did you find this page helpful?