-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
fix: set cookies when throwing redirect in handle #8648
fix: set cookies when throwing redirect in handle #8648
Conversation
🦋 Changeset detectedLatest commit: c60d9b3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
throw redirect()
response in handle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I think we need to apply the same logic to the case where it's a __data.json
request (the if branch above the changed code)
@@ -296,7 +300,15 @@ export async function respond(request, options, manifest, state) { | |||
if (is_data_request) { | |||
return redirect_json_response(e); | |||
} else { | |||
return redirect_response(e.status, e.location); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can keep the redirect_response
function and add the headers to it.
const response = redirect_response(..);
add_cookies_to_headers(..);
return response;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to do it this way originally but wasn't sure if only cookies should be added or to include the headers from setHeaders()
too.
I also didn't want a location
header from setHeaders
to overwrite the thrown redirect location.
Maybe I can extend the redirect_response()
helper to optionally accept a headers
option?
I noticed there were similar redirect responses in the file not using the helper just so that it could add other headers to it.
Thank you! |
Thanks for the guidance! |
fixes #8643
Adds headers and cookies to the response when using
throw redirect
inhandle
so that it behaves similarly to returning a new redirectResponse
inhandle
.I'm sure there's a more elegant approach to this fix and the test, but I can't quite figure it out (this is my first time writing a test). Would appreciate any suggested changes.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.