You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Change isAuthenticated in the docs from boolean to boolean | undefined or something else that reflects a loading state. Adjust code to be appropriate.
The only way I've found to make it work is through a custom useUser() => User hook but I'd love to know if there's a correct way to do it with Router context. Unfortunately the documentation example breaks pretty badly when trying this.
Explanation of the Problem
The docs all treat authentication as a boolean state.
Unfortunately in client side code we have also have to deal with isAuthenticated: undefined while we asynchronously load the authentication from a server.
This will cause the user to be redirected to the sign in page while the auth is still loading. I'd consider this inappropriate to do unless the user is known to be signed out, but we also don't want to let them proceed to the authenticated page.
The auth will still be loading, so the throw redirect is not triggered.
Shortly after the auth will be loaded.
This can lead to a signed-in user sitting on the loaded /sign-in page. They've already passed the beforeLoad, so there's nothing to trigger the redirect. It's possible to hack around it with useEffect or something similar but it's ugly.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
TL;DR
Change
isAuthenticated
in the docs fromboolean
toboolean | undefined
or something else that reflects a loading state. Adjust code to be appropriate.The only way I've found to make it work is through a custom
useUser() => User
hook but I'd love to know if there's a correct way to do it with Router context. Unfortunately the documentation example breaks pretty badly when trying this.Explanation of the Problem
The docs all treat authentication as a boolean state.
Unfortunately in client side code we have also have to deal with
isAuthenticated: undefined
while we asynchronously load the authentication from a server.eg. from the Clerk types:
This causes a significant issue with the recommended auth pattern of using
beforeLoad
.This will cause the user to be redirected to the sign in page while the auth is still loading. I'd consider this inappropriate to do unless the user is known to be signed out, but we also don't want to let them proceed to the authenticated page.
They then hit the
beforeLoad
onsign-in.tsx
The auth will still be loading, so the
throw redirect
is not triggered.Shortly after the auth will be loaded.
This can lead to a signed-in user sitting on the loaded
/sign-in
page. They've already passed thebeforeLoad
, so there's nothing to trigger theredirect
. It's possible to hack around it withuseEffect
or something similar but it's ugly.Evidence of Need
(and probably more but I think the point is made)
Beta Was this translation helpful? Give feedback.
All reactions