how to use dynamic routes in middleware.js #5010
Unanswered
dhavalveera
asked this question in
Help
Replies: 2 comments 9 replies
-
The matcher follow the same logic as the routes in Next.js. In your case. If you want to protect both "/product" route and the "/product/[productId]" route you would write your middleware this way:
|
Beta Was this translation helpful? Give feedback.
9 replies
-
You have the possibility to match like this for this path:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I was looking in the NextAuth documentation to protect the pages using the middleware.js file, and I found the code snippet from NextAuth's Documentation.
here, I have a question, as in
matcher
it passes the regular page (file) name, but how to protect the dynamic pages? e.g./pages/[productId]/index.js
or/pages/product/[index].js
, how to protect those kinds of pages using themiddleware.js
file?also, as per the example shared above, if I hit the
URL/dashboard
page directly then it'll redirect to the Login page, then after successful Login, does it'll redirect back to the Dashboard Page?also, if I use a Custom Login Page instead of NextAuth's default Login Page, then this
middleware
will work the same way?please explain/help me here.
Beta Was this translation helpful? Give feedback.
All reactions