-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: set cookies followed by
redirect()
(#49965)
- Fixes #49237 fix NEXT-1120 Co-authored-by: Wyatt Johnson <[email protected]>
- Loading branch information
Showing
12 changed files
with
129 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 16 additions & 24 deletions
40
packages/next/src/server/future/route-modules/helpers/response-handlers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,29 @@ | ||
export function handleTemporaryRedirectResponse(url: string): Response { | ||
return new Response(null, { | ||
status: 302, | ||
statusText: 'Found', | ||
headers: { | ||
location: url, | ||
}, | ||
}) | ||
import { appendMutableCookies } from '../../../web/spec-extension/adapters/request-cookies' | ||
import { ResponseCookies } from '../../../web/spec-extension/cookies' | ||
|
||
export function handleTemporaryRedirectResponse( | ||
url: string, | ||
mutableCookies: ResponseCookies | ||
): Response { | ||
const headers = new Headers({ location: url }) | ||
|
||
appendMutableCookies(headers, mutableCookies) | ||
|
||
return new Response(null, { status: 307, headers }) | ||
} | ||
|
||
export function handleBadRequestResponse(): Response { | ||
return new Response(null, { | ||
status: 400, | ||
statusText: 'Bad Request', | ||
}) | ||
return new Response(null, { status: 400 }) | ||
} | ||
|
||
export function handleNotFoundResponse(): Response { | ||
return new Response(null, { | ||
status: 404, | ||
statusText: 'Not Found', | ||
}) | ||
return new Response(null, { status: 404 }) | ||
} | ||
|
||
export function handleMethodNotAllowedResponse(): Response { | ||
return new Response(null, { | ||
status: 405, | ||
statusText: 'Method Not Allowed', | ||
}) | ||
return new Response(null, { status: 405 }) | ||
} | ||
|
||
export function handleInternalServerErrorResponse(): Response { | ||
return new Response(null, { | ||
status: 500, | ||
statusText: 'Internal Server Error', | ||
}) | ||
return new Response(null, { status: 500 }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { draftMode } from 'next/headers' | ||
import { redirect } from 'next/navigation' | ||
|
||
export function GET() { | ||
draftMode().enable() | ||
return redirect('/some-other-page') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters