punn
punn2y ago

storeUser pattern for Clerk is flaky

I followed the storeUser pattern for storing a user with Clerk as the auth provider. One issue I'm running into is inconsistency with the the auth object in MutationCtx. It frequently throws the error below and only occasionally after a few refreshes does the mutation run correctly. I call storeUser on the client right when the user logs in (redirect after login). I notice that storeUser is only correctly called after reloading the page again or hotreloading with a filesave.
No description
4 Replies
ian
ian2y ago
Before running your storeUser mutation, are you checking the isAuthenticated value from useConvexAuth() or is it in an <Authenticated> subtree? After Clerk logs in, the ConvexProviderWithClerk sets the auth token with Convex, and only when it's done will mutations have access to auth.
ian
ian2y ago
lmk if that doesn't make sense, or if you're still seeing issues. I noticed that the storeUser docs don't make it clear where this useEffect should live. Filing a ticket to improve that, sorry!
punn
punnOP2y ago
Ah gotcha I haven't actually used isAuthenticated and was relying mostly on the isSignedIn from useUser() will give that a shot thanks! Awesome that fixed it thank you

Did you find this page helpful?