Skip to content
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 cookie headers not being added to response #5151

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions server/vue-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,23 @@ async function render(context) {
}
});

const setCookies = [];
let setCookies = [];

return Promise.all([typesPromise, cookiePromise])
.then(([types, cookieInfo]) => {
// add fetched types to rendering context
context.config.graphqlPossibleTypes = types;
// update cookies in the rendering context with any newly fetched session cookies
context.cookies = Object.assign(context.cookies, cookieInfo.cookies);
// forward any newly fetched 'Set-Cookie' headers
context.setCookies = [...cookieInfo.setCookies];
// collect any newly fetched 'Set-Cookie' headers to send after the render
setCookies = [...cookieInfo.setCookies];
// render the app
return renderer.renderToString(context);
})
.then(html => {
// collect any cookies created during the app render
setCookies.concat(context.setCookies);
const contextSetCookies = context?.setCookies ?? [];
setCookies = [...setCookies, ...contextSetCookies];
// send the final rendered html
return {
html,
Expand All @@ -71,7 +72,8 @@ async function render(context) {
})
.catch(err => {
// collect any cookies created during the app render
setCookies.concat(context.setCookies);
const contextSetCookies = context?.setCookies ?? [];
setCookies = [...setCookies, ...contextSetCookies];
// send the error
return {
error: err,
Expand Down
Loading