Implement AuthWrapper in filebased routing
How do I implemement the following code in my filebased router?
9 Replies
eastern-cyanOP•2y 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
fair-rose•2y 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.
eastern-cyanOP•2y 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
fair-rose•2y 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.
eastern-cyanOP•2y ago
So I can have something like a
_protected.jsx layout route file and use beforeLoad in that?fair-rose•2y ago
Yea
eastern-cyanOP•2y ago
Currently each of my routes is setup in different files.
fair-rose•2y ago
Just, make them all a child of the layout route. It won't affect the URLs, so you should be fine.
eastern-cyanOP•2y ago
Okay I've implemented something based on what you've said and the docs,
This is a layout route