Skip to content

Commit

Permalink
Merge pull request #5151 from kiva/vue-worker-set-cookie-fix
Browse files Browse the repository at this point in the history
fix: set cookie headers not being added to response
  • Loading branch information
mcstover authored Jan 31, 2024
2 parents f265a0d + 2741ab0 commit 8c8276a
Showing 1 changed file with 7 additions and 5 deletions.
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

0 comments on commit 8c8276a

Please sign in to comment.