K
Kinde3mo ago
Samyam

Protect all routes except some public ones

Is there any workaround for this, I want to protect all routes but exclude the main '/', i am using layout for route protection but it is making all my pages dynamically rendered, i want them to be static, I tried regex but it didn't work, i could protect every route but couldn't add excluded routes.
No description
4 Replies
IkiTg07
IkiTg073mo ago
Hey, have you tried middleware ? You can use a matcher to exclude "/" Here's an example of middleware
No description
Samyam
SamyamOP3mo ago
My apologies, I am aware of the middleware but the middleware only protects certain routes, what i wanted to do is to create a middleware what protects all routes by default and if the user is not logged in , it redirects to the login page. But due to next.js caching, it causes issues during authentication as the image states. I wanted to know if there is a workaround for the problem
IkiTg07
IkiTg073mo ago
Mmm yeah, I don’t see another way of doing that if not having your logic in the root layout of your app. You can use a wrapper like you have when using something like jotai or next themes. You create a KindeProvider or some like that and put your logic in there. Or you can just have it directly in the root layout file
Samyam
SamyamOP3mo ago
yes the problem is when building, those routes that are authenticated that way are always dynamic routes
No description
Want results from more Discord servers?
Add your server