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

Cannot access NextRequest headers in framework middleware under Edge runtime #148

Closed
jameslshannon opened this issue Mar 23, 2024 · 2 comments

Comments

@jameslshannon
Copy link

jameslshannon commented Mar 23, 2024

Node 18.18.2, Next JS 14.1.3 and framework 5.1.11

RouteOperationDefinition excerpt:
<snip>
   .middleware((req: NextRequest) => {
      console.log(req.headers.get('Authorization'))
      return { request: req }
    })
    .handler(async (req, ctx, { request }) => {
        console.log(request.headers.get('Authorization'))
        console.log(req.headers.get('Authorization'))
<snip>

When I run the above code using Vercel dev under the standard Node runtime locally I get 3 successful logs of the Authorization header, but when I run it under the Edge runtime locally I only get the final log of the Authorization header, so for some reason the middleware NextRequest doesn't have the Authorization header in Edge runtime - even though my main Next middleware can access it fine. Other properties of the NextRequest object seem to be available in the middleware apart from any of the headers.

The framework middleware would be a great place to enforce handler-specific authorization rules if access to the request headers was supported.

Thanks,

James

@jameslshannon jameslshannon changed the title Can't access Authorization header in framework middleware under Edge runtime Cannot access NextRequest headers in framework middleware under Edge runtime Mar 24, 2024
@blomqma
Copy link
Owner

blomqma commented Mar 24, 2024

Thanks, this is about to get fixed in the next release with #144 that improves the support for handling forms. The request object is currently incorrectly cloned for the middleware functions causing the headers not be present there.

@blomqma
Copy link
Owner

blomqma commented Mar 24, 2024

After upgrading to 6.0.0-beta.1 you should see this addressed.

@blomqma blomqma closed this as completed Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants