Waiting for session to load with useSession()
# help-and-questions
m
When using useSession() from the auth-helpers-react, how do I wait for the session to be loaded? I am trying to redirect the user to sign in page, if there is no session. But it seems that the session is always NULL before the session is set to the session value or NULL. How do I make sure whether the session is actually null, and no just loading?
n
I'm also interested in this. I found client side to be a bit tricky with this. Could you try check the
isLoading
param from the
useSessionContext
? As an old workaround for nextjs, I used middleware to check for session for protected routes. It's fast enough for my use case.
m
How do you do that nextjs middleware? I could also try the isLoading for the context.
n
Try isLoading first. I think it's what you want. When I wrote my code,
useSession
was a bit unreliable, but it's been a long time since then.
you can check the middleware section on auth helpers doc.
It should be the same
m
Alright thank you!
2 Views