Next.js Discord

Discord Forum

NextResponse.next()

Unanswered
Black Rail posted this in #help-forum
Open in Discord
Black RailOP
This middleware's code includes NextResponse.next() command twice. First or second works depending on my conditions. I forward with debug. In the first NextResponse.next() command worked but when the code satisfies the second condition i can stand on the line with debug and go forward one line this doesnt go to next function. How can the same code give different results when run above and different results when run below? In brief first NextResponse.next goes the next function but second NextResponse.next doesnt go to next function and it doesnt give me error.

1 Reply

Try creating headers like in official example:

const requestHeaders = new Headers(request.headers)
  requestHeaders.set('x-hello-from-middleware1', 'hello')


Docs: https://nextjs.org/docs/app/building-your-application/routing/middleware#setting-headers