Fixes: Cookie encoding issues

This commit is contained in:
Tom Moor
2019-02-28 23:23:44 -08:00
parent e3b105d1c0
commit b4796e5b35
5 changed files with 26 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,

View File

@@ -15,7 +15,9 @@ const sheet = new ServerStyleSheet();
export default function renderpage(ctx: Object, children: React.Node) {
let sessions = {};
try {
sessions = JSON.parse(ctx.cookies.get('sessions') || '{}');
sessions = JSON.parse(
decodeURIComponent(ctx.cookies.get('sessions') || '') || '{}'
);
} catch (err) {
console.error(`Sessions cookie could not be parsed: ${err}`);
}