Skip to content
Discussion options

You must be logged in to vote

You can't use context in data or framework mode to define what routes exists, the routes needs to be defined before that so the router can optimize how data is loaded on navigation.

So the way to do it is by storing auth state outside React (not using a React state) in a way you can do getUser() in loader and actions, where to store this depends on you, it can be as simple as using localStorage, if you use some external store like Zustand or Redux that also works as you can always do store.getState() in the loaders, or you could use a cookie and then fetch the user from the API every time you need it.

Then you can perform authentication and authorization in the loaders/actions to allow th…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@XCanG
Comment options

@XCanG
Comment options

@sergiodxa
Comment options

Answer selected by XCanG
@XCanG
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants