Next.js 15 middleware
Unanswered
Northeast Congo Lion posted this in #help-forum
Northeast Congo LionOP
I am looking to try out Next.js 15 for my frontend and I want to implement route guards to protects routes of different users. Will the Next.js middleware be triggered even when the built-in Link component is used for navigation? We no longer have to add the x-middleware-cache: no-cache header to run middleware always for every route, right?
6 Replies
Schneider’s Smooth-fronted Caiman
I have a nextjs 15 site with an admin section that uses auth0 for authentication. The middleware gets called when I click on a <Link> in my admin sidebar.
I protect both via the middleware (logged in) and via the layout (role verification)
@Schneider’s Smooth-fronted Caiman I protect both via the middleware (logged in) and via the layout (role verification)
Northeast Congo LionOP
In previous versions of Next.js, I used a RouteControl higher order component to control navigation to routes of different users. I was originally planning to use just the middleware to manage this. Won't that be enough or is a layout mandatory?
Schneider’s Smooth-fronted Caiman
I'm not an expert in this. You can probably do it in the middleware, I just chose to do it in the layout/client-side because I also conditionally show UI elements based on the role.
you can get the session in the middleware, and with auth0 that's enough to get the RBAC info, so I assume middleware-based would work fine. But again, not an expert in this, just a guy hacking stuff together with what I can understand from online docs 😄
@Schneider’s Smooth-fronted Caiman you can get the session in the middleware, and with auth0 that's enough to get the RBAC info, so I assume middleware-based would work fine. But again, not an expert in this, just a guy hacking stuff together with what I can understand from online docs 😄
Northeast Congo LionOP
I guess that's how all devs learn. Appreciate your help 😄