DEV Community

Discussion on: Middleware in Next.js: Moving from Express

Collapse
 
crhistianramirez profile image
Crhistian Ramirez

Hey Hunter, good read. I'm really curious how this would work now that NextJS has added support for middleware directly (in v12). Specifically struggling to understand how to do something like withRoles. Ideally I'd want to define something at the route level that indicates which roles are required to access that route, and then the middleware would be able to use that information to guard against that route.

Haven't really found anything that supports this use case. I think I'm just going to have a base middleware that validates that the token, and then use something like your withRoles HOC to validate the roles at the endpoint level.