Fixes: Unexpected token parsing sessions cookie (#905)

This commit is contained in:
Tom Moor
2019-03-02 14:58:56 -08:00
committed by GitHub
parent e3b105d1c0
commit fa38ab60eb
6 changed files with 27 additions and 20 deletions

View File

@ -115,15 +115,19 @@ export default function auth(options?: { required?: boolean } = {}) {
// to the teams subdomain if subdomains are enabled
if (process.env.SUBDOMAINS_ENABLED === 'true' && team.subdomain) {
// get any existing sessions (teams signed in) and add this team
const existing = JSON.parse(ctx.cookies.get('sessions') || '{}');
const sessions = JSON.stringify({
...existing,
[team.id]: {
name: encodeURIComponent(team.name),
logoUrl: team.logoUrl,
url: encodeURIComponent(team.url),
},
});
const existing = JSON.parse(
decodeURIComponent(ctx.cookies.get('sessions') || '') || '{}'
);
const sessions = encodeURIComponent(
JSON.stringify({
...existing,
[team.id]: {
name: team.name,
logoUrl: team.logoUrl,
url: team.url,
},
})
);
ctx.cookies.set('sessions', sessions, {
httpOnly: false,
expires,