Async Req for Context
Hey when setting up my app, I want to query the server to see if the user is logged in (redirect to login-in page if not)
Is there a better way to do this than having the loading state?
4 Replies
stormy-gold•10mo ago
beforeLoad is a nice place for this case
If you don't want to checkup on every route, you could group routes into (protected)/(public) routes and use beforeLoad in each of them
and check like such
automatic-azureOP•10mo ago
Thanks, that'll work for what I need.
Is the recommended approach to show the loading state while fetching? I didn't see an async example in the docs.
Is the recommended approach to show the loading state while fetching? I didn't see an async example in the docs.
stormy-gold•10mo ago
I would save the user in a session after authentication, that way getting the user from the context is constant and no need for loading states, just my opinion though
automatic-azureOP•10mo ago
Yeah, sounds like a good solution. Thanks for the help