Implement AuthWrapper in filebased routing
How do I implemement the following code in my filebased router?
9 Replies
relaxed-coralOP•15mo ago
I have the AuthWrapper setup and root route setup in my
_index.jsx
file whereas all the other routes like login, signup, etc are setup in their own login.jsx
, signup.jsx
files and etc like so,
_root.jsx
login.jsx
and other sub routes are created similarly
how can I implement the above code with respect to my setup?
My Auth wrapper goes something like this
unwilling-turquoise•15mo ago
You could achieve this with a layout route
Have you looked at the authenticated routes example?
Its a matter if putting your auth wrapper logic in the layout route over there.
relaxed-coralOP•15mo ago
I did! But I was just wondering if there was a way without having to check for auth status and redirect on every protected route since my entire application except login and sign up pages is protected
unwilling-turquoise•15mo ago
That's where the layout route comes in. You'll only be checking it in there.
The child routes of the layout can be considered to already be authenticated.
relaxed-coralOP•15mo ago
So I can have something like a
_protected.jsx
layout route file and use beforeLoad
in that?unwilling-turquoise•15mo ago
Yea
relaxed-coralOP•15mo ago
Currently each of my routes is setup in different files.
unwilling-turquoise•15mo ago
Just, make them all a child of the layout route. It won't affect the URLs, so you should be fine.
relaxed-coralOP•15mo ago
Okay I've implemented something based on what you've said and the docs,
This is a layout route