Quick way to protect all routes under a certain parent route in nextjs (app router)?
Is there any way I can try and automatically run a function (I guess some kind of middleware) to determine a user's level of auth (I'll have access to this via an API call), and then prevent the render of said page and redirect, only under a certain route and its children?
6 Replies
You can redirect in the middleware
thanks at @xchristoph , I had a hunch that'd be the case. Are there any examples you know of online off the top of your head? I'm looking for some now
Routing: Middleware
Learn how to use Middleware to run code before a request is completed.
Should be documented rather well in the official docs.
Ignore me, found the right docs 😅
It's basically just configuring the correct matcher, one if-statement and a Response.redirect call.