Skip to content

Best practice around authentication checks in nested routes #12510

Closed Answered by sergiodxa
discoverlance-com asked this question in Q&A
Discussion options

You must be logged in to vote

Do I need to call the requireUser function in every authenticated layout? For example, I have the nested route structure, /dashboard/events and /dashboard/events/create. Do I need to call the requireUser function in the parent layouts and all child routes or do I only need to add it in the parent layout? Are there any gotchas for when I only add it in the layout? I know react router will load the data in parallel and revalidate so I should be covered if I only load it in the dashboard.tsx layout file right?

You need to check for auth in every loader and actions that needs to be protected (it's not public), every loader/action can be fetched individually so not adding your auth check wil…

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
6 replies
@sergiodxa
Comment options

@discoverlance-com
Comment options

@sergiodxa
Comment options

@discoverlance-com
Comment options

@michaeljblum
Comment options

Answer selected by discoverlance-com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants