Middleware match path like this (admin) folder?
Answered
Transvaal lion posted this in #help-forum
Transvaal lionOP
I have a folder named (admin) that has my admin stuff , I want to use middleware to protect all pages in the folder
https://nextjs.org/docs/app/building-your-application/routing/middleware
but based on the doc, it
my folder structure is like this
and I want to protect all these pages
https://nextjs.org/docs/app/building-your-application/routing/middleware
but based on the doc, it
MUST start with /, does that mean it is not possible to protect the entire folder?my folder structure is like this
(admin)
-- stats
---- page.tsx
-- logs
---- page.tsx
...and I want to protect all these pages
6 Replies
Transvaal lionOP
something like this does not work
if (request.nextUrl.pathname.startsWith('/(admin)')) {{@Transvaal lion something like this does not work `if (request.nextUrl.pathname.startsWith('/(admin)')) {{`
yeah we need to do this
if (["/stats", "/logs"].includes(request.nextUrl.pathname))Transvaal lionOP
there is no way to block access for all subfolders inside that folder?
adding them manually seems a bit difficult if I add more folders and pages
@Transvaal lion there is no way to block access for all subfolders inside that folder?
yes but not a route group
Answer
eg. create a route
/admin