Next.js Discord

Discord Forum

Middleware

Unanswered
Exzotic posted this in #help-forum
Open in Discord
How could I protect certain folders such as anything in (authed) to need next-auth middleware. I have my middleware in src/middleware.ts as it seems it only works there and no where else but then it seems restricted to just one middleware on the whole project?

6 Replies

Giant panda
The middleware has a config allowing to set which paths to match for
You can match on your pages requiring auth in there.
Check the docs for the middleware config, there are multiple examples for that.
Is it possible to match by the (...) folders that arent really a path?
Giant panda
No you have to match by actual URLs
ah alright, might be easier to just exclude certain urls then