erikras / erikras/react-redux-universal-hot-example

Passing API's Set-cookie through to the browser

Open
#1,230 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
12.1k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

Hi all,

I'm trying to pass through a Set-cookie header from my API to the browser, and want to run my potential solution by you to get feedback/ask if it's safe. Being authentication I wanted second opinions first before going live with it.

Basically in ApiClient.js I save the set-cookies returned from the API to a global variable (global.setCookies):

```
request.end((err, { body, header } = {}) => {
if (typeof header['set-cookie'] !== 'undefined') {
const setCookies = header['set-cookie'];

if (typeof global.setCookies === 'undefined') {
global.setCookies = [];
}

global.setCookies = global.setCookies.concat(setCookies);
}

return err ? reject(body || err) : resolve(body);
});
```

Then in src/server.js I set them before returning the result (and clear them before the next request):

```
for (let idx = 0; idx < global.setCookies.length; idx++) {
res.append('Set-Cookie', global.setCookies[idx]);
}

global.setCookies = [];
```

I guess my biggest concern is if they are stored globally, could then end up in someone elses request?

Hope that all makes sense :)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.