T
TanStack8mo ago
genetic-orange

Need advice on authentication

https://stackblitz.com/~/github.com/RenZin12/test-tanstack-router Here is my authenticated routes. The username is "Bob" and password is "123". In my backend, I am using session authentication. I am still quite new to React and TanStack router so I am still confuse on how they all come together. I realized that root route's beforeLoad() runs before a useEffect() in the <AuthProvider>, therefore I decide to run my getAuthStatus() in root route's beforeLoad(). However, I return the new context in the beforeLoad() here, because after router.invalidate() is called, it seems even though I set the state with new values in getAuthStatus(), it won't update before the beforeLoad() in '/login' route runs. I came up with this while trying to follow the authenticated route example in the documentation, which is why there is similarities. I am not sure if this is a good way to go about it. I don't believe it is, which is why I am asking for advice. Thank you.
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?