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

@@ -1,7 +1,7 @@
// @flow
import { observable, action, computed, autorun, runInAction } from 'mobx';
import invariant from 'invariant';
import Cookie from 'js-cookie';
import { getCookie, setCookie, removeCookie } from 'tiny-cookie';
import { client } from 'utils/ApiClient';
import { stripSubdomain } from 'shared/utils/domains';
import RootStore from 'stores/RootStore';
@@ -31,7 +31,7 @@ export default class AuthStore {
this.rootStore = rootStore;
this.user = data.user;
this.team = data.team;
this.token = Cookie.get('accessToken');
this.token = getCookie('accessToken');
if (this.token) setImmediate(() => this.fetch());
@@ -138,15 +138,15 @@ export default class AuthStore {
this.token = null;
// remove authentication token itself
Cookie.remove('accessToken', { path: '/' });
removeCookie('accessToken', { path: '/' });
// remove session record on apex cookie
const team = this.team;
if (team) {
const sessions = Cookie.getJSON('sessions') || {};
const sessions = JSON.parse(getCookie('sessions') || '{}');
delete sessions[team.id];
Cookie.set('sessions', JSON.stringify(sessions), {
setCookie('sessions', JSON.stringify(sessions), {
domain: stripSubdomain(window.location.hostname),
});
this.team = null;