Seems like convex auth isn't setting user immediately
for some reason so if I redirect to a page that checks if there is a valid user if there isn't it redirects me back to sign in so now immediately I redirect to "/dashboard" it redirects me back to "/sign-in"
My code for getting currently logged in user
The Component
8 Replies
In the client you're calling the query right away whether the user is authenticated or not. Pass "skip" to the query instead of an object until the user is authenticated in the client.
It still doesn't fix it
isAuthenticated should be true immediately I sign up right I logged it, it is false so it redirects me back to sign in
isLoading is false while isAuthenticated also is still false
isAuthenticated should be true immediately (after) I sign up rightThis isn't true --
isAuthenticated
is true once signUp / singIn has finished, and its result has been processed by the Convex backend. So there's a potential race between isAuthenticated
flipping to true and your query running, which is why sometimes you'd see log lines with isAuthenticated
as true before your query runs, but to get the correct behavior every time, you'll want to skip your query when isAuthenticated
is false, as erquhart suggested.
isAuthenticated
and isLoading
should both be false only when the user is unauthenticated, so the redirect is the second useEffect looks fine to me.
If you're still seeing your query run without a user with this fix, could you turn on verbose logging (new ConvexReactClient(url, { verbose: true })
) and share the logs?Okay so this is what I have currently
After I just signed in
I got this isLoading and isAuthenticated is false
After signing up isAuthenticated is false and isLoading is also false
Can you share the code for your sign up page too? These are also both nested underneath the same
ConvexAuthProvider
, right?I would share that now
The thing is something isAuthenticated is false and sometimes after sign up isAuthenticated is true there is inconsistency
Yeah I have just one
ConvexAuthProvider
wrapping the entire app
This is the logic in the component the rest are just jsx
Sign in also has the same issue but once I reload and change the url to dashboard it gets that they are authenticated
It just doesn't make sense cause why do I need to hard reload for it to work?Indeed right now you have to wait for isAuthenticated manually:
https://github.com/get-convex/convex-auth/issues/29
GitHub
Block
signIn
function on completed signIn
· Issue #29 · get-con...Right now there's a delay between signIn finishing and the client authenticating. This leads to a visible "bug" for email+password requiring verification: Sign up Verify Log out Sign ...