Getting client pathname in middleware
Answered
ncls. posted this in #help-forum
ncls.OP
Hi, I'm currently doing some special protecting routes stuff.
When the user enters the
Is there a way I can get the route the user is seeing in their browser?
When the user enters the
/signin page, the middleware should check wether they are already authenticated or not. However, req.nextUrl.pathname does not return /signin I expected, but rather /_next/static/chunks/app/(auth)/signin/page.js which is really uncomfortable to work with and unpractical.Is there a way I can get the route the user is seeing in their browser?
Answered by European sprat
but if you are excluding signin in the matcher... of course it's not going to run lol
6 Replies
European sprat
You sure it doesn't show the path after that? You likely want to use the matcher to exclude static files from being handled in middleware to avoid seeing them
@European sprat You sure it doesn't show the path after that? You likely want to use the matcher to exclude static files from being handled in middleware to avoid seeing them
ncls.OP
I am using matcher (which should actually cause the middleware not to run at all on
Also what do you mean with "show the path after that"?
/signin LMAO but it does):export const config = {
matcher: [ '/((?!api/auth|signin|assets).*)' ],
}Also what do you mean with "show the path after that"?
I looked through the
req.nextUrl object but couldn't find anything that matched what I needEuropean sprat
i mean it shows the hit on the static asset but then after that does it not show the hit on the path you want to check?
European sprat
but if you are excluding signin in the matcher... of course it's not going to run lol
Answer
@European sprat but if you are excluding signin in the matcher... of course it's not going to run lol
ncls.OP
I am an idiot LMAO
Thank you XD
Thank you XD