Skip to content

Commit 64f73f3

Browse files
VIA-357 MD/DB Fix middleware adding extra request headers to only modify request, not response
In the previous implementation the headers sent into the NextResponse.next method get applied to both the inbound reuqest AND override the response headers as well. This unintended manipulation of the response headers causes errors when calling Server Actions, where next.js expects a particular content-type in the response and the framework will throw an unhandled error if the header is not set as expected.
1 parent c85d0d1 commit 64f73f3

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/middleware.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ const middlewareWrapper = async (request: NextRequest) => {
3333
log.info({ context: { nextUrl: request.nextUrl.href } }, "Missing user session, redirecting to login");
3434
response = NextResponse.redirect(new URL(config.NHS_APP_REDIRECT_LOGIN_URL));
3535
} else {
36-
response = NextResponse.next({ headers });
36+
response = NextResponse.next({
37+
request: { headers: headers },
38+
});
3739
}
3840

3941
profilePerformanceEnd(MiddlewarePerformanceMarker);

0 commit comments

Comments
 (0)