Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NextRequest.url & NextRequest.nextUrl.pathname return public assets #32361

Closed
fikriwebdev opened this issue Dec 10, 2021 · 3 comments
Closed
Labels
please add a complete reproduction The issue lacks information for further investigation

Comments

@fikriwebdev
Copy link

What version of Next.js are you using?

12

What version of Node.js are you using?

16

What browser are you using?

chrome

What operating system are you using?

windows

How are you deploying your application?

vercel

Describe the Bug

I am using middleware for authentication and using _middleware.ts on pages root. I want to make sure the middleware only runs on pages that are not /login so i have to check if url !== "/login" but this is error because url return public assets to like manifest.json, image and etc.
error

Expected Behavior

i want NextRequest.url only return pages not public assets

To Reproduce

as described above

@fikriwebdev fikriwebdev added the bug Issue was opened via the bug report template. label Dec 10, 2021
@fikriwebdev
Copy link
Author

i am trying to find a solution and got some solution is to make middleware in every pages but i dont include the middleware on root of pages. Its work as expected but when i am trying to deploy to vercel its error

WhatsApp Image 2021-12-09 at 19 32 09

@balazsorban44 balazsorban44 added please add a complete reproduction The issue lacks information for further investigation and removed bug Issue was opened via the bug report template. labels Dec 10, 2021
@balazsorban44
Copy link
Member

balazsorban44 commented Dec 10, 2021

The root middleware is expected to run on public files as well. #30187 (comment)

As for the deployment, I will need a reproduction to be able to help.

UPDATE: The issue in the linter has been fixed in 12.0.8-canary.0 and newer through this PR: #32139

You can try out yarn add next@canary or wait until it's released to latest.

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
please add a complete reproduction The issue lacks information for further investigation
Projects
None yet
Development

No branches or pull requests

2 participants