Skip to content

Commit 3a1aad0

Browse files
authored
fix(nextjs): Return NextResponse instead of native Response (#6388)
1 parent 3290039 commit 3a1aad0

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

.changeset/olive-sides-allow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/nextjs': patch
3+
---
4+
5+
Fixes an issue where `clerkMiddleware()` would not properly redirect or set cookies in some environments.

packages/nextjs/src/server/clerkMiddleware.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,14 @@ export const clerkMiddleware = ((...args: unknown[]): NextMiddleware | NextMiddl
195195

196196
const locationHeader = requestState.headers.get(constants.Headers.Location);
197197
if (locationHeader) {
198-
return new Response(null, { status: 307, headers: requestState.headers });
198+
const res = NextResponse.redirect(locationHeader);
199+
requestState.headers.forEach((value, key) => {
200+
if (key === constants.Headers.Location) {
201+
return;
202+
}
203+
res.headers.append(key, value);
204+
});
205+
return res;
199206
} else if (requestState.status === AuthStatus.Handshake) {
200207
throw new Error('Clerk: handshake status without redirect');
201208
}

0 commit comments

Comments
 (0)