Added cookie to indicate logged in status
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import { observable, action, computed, autorunAsync } from 'mobx';
|
import { observable, action, computed, autorunAsync } from 'mobx';
|
||||||
import invariant from 'invariant';
|
import invariant from 'invariant';
|
||||||
|
import Cookie from 'js-cookie';
|
||||||
import { client } from 'utils/ApiClient';
|
import { client } from 'utils/ApiClient';
|
||||||
import type { User, Team } from 'types';
|
import type { User, Team } from 'types';
|
||||||
|
|
||||||
@ -33,6 +34,7 @@ class AuthStore {
|
|||||||
@action logout = () => {
|
@action logout = () => {
|
||||||
this.user = null;
|
this.user = null;
|
||||||
this.token = null;
|
this.token = null;
|
||||||
|
Cookie.remove('loggedId', { path: '/' });
|
||||||
};
|
};
|
||||||
|
|
||||||
@action getOauthState = () => {
|
@action getOauthState = () => {
|
||||||
|
@ -52,6 +52,7 @@ class ApiClient {
|
|||||||
body,
|
body,
|
||||||
headers,
|
headers,
|
||||||
redirect: 'follow',
|
redirect: 'follow',
|
||||||
|
credentials: 'include',
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle request promises and return a new promise
|
// Handle request promises and return a new promise
|
||||||
|
@ -77,7 +77,7 @@
|
|||||||
"babel-preset-react": "6.11.1",
|
"babel-preset-react": "6.11.1",
|
||||||
"babel-preset-react-hmre": "1.1.1",
|
"babel-preset-react-hmre": "1.1.1",
|
||||||
"babel-regenerator-runtime": "6.5.0",
|
"babel-regenerator-runtime": "6.5.0",
|
||||||
"bcrypt": "^0.8.7",
|
"bcrypt": "1.0.3",
|
||||||
"boundless-arrow-key-navigation": "^1.0.4",
|
"boundless-arrow-key-navigation": "^1.0.4",
|
||||||
"boundless-popover": "^1.0.4",
|
"boundless-popover": "^1.0.4",
|
||||||
"bugsnag": "^1.7.0",
|
"bugsnag": "^1.7.0",
|
||||||
@ -107,6 +107,7 @@
|
|||||||
"imports-loader": "0.6.5",
|
"imports-loader": "0.6.5",
|
||||||
"invariant": "^2.2.2",
|
"invariant": "^2.2.2",
|
||||||
"isomorphic-fetch": "2.2.1",
|
"isomorphic-fetch": "2.2.1",
|
||||||
|
"js-cookie": "^2.1.4",
|
||||||
"js-search": "^1.4.2",
|
"js-search": "^1.4.2",
|
||||||
"js-tree": "1.1.0",
|
"js-tree": "1.1.0",
|
||||||
"json-loader": "0.5.4",
|
"json-loader": "0.5.4",
|
||||||
|
@ -47,6 +47,14 @@ router.post('auth.slack', async ctx => {
|
|||||||
await team.createFirstCollection(user.id);
|
await team.createFirstCollection(user.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Signal to backend that the user is logged in.
|
||||||
|
// This is only used to signal SSR rendering, not
|
||||||
|
// used for auth.
|
||||||
|
ctx.cookies.set('loggedId', 'true', {
|
||||||
|
httpOnly: false,
|
||||||
|
expires: new Date('2100'),
|
||||||
|
});
|
||||||
|
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
data: {
|
data: {
|
||||||
user: await presentUser(ctx, user),
|
user: await presentUser(ctx, user),
|
||||||
|
@ -1,21 +1,22 @@
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import fs from 'fs';
|
||||||
import httpErrors from 'http-errors';
|
import httpErrors from 'http-errors';
|
||||||
import Koa from 'koa';
|
import Koa from 'koa';
|
||||||
import Router from 'koa-router';
|
import Router from 'koa-router';
|
||||||
import sendfile from 'koa-sendfile';
|
import sendfile from 'koa-sendfile';
|
||||||
|
|
||||||
import subdomainRedirect from './middlewares/subdomainRedirect';
|
import subdomainRedirect from './middlewares/subdomainRedirect';
|
||||||
|
|
||||||
const koa = new Koa();
|
const koa = new Koa();
|
||||||
const router = new Router();
|
const router = new Router();
|
||||||
|
|
||||||
router.get('/service-worker.js', async ctx => {
|
const readFile = src => {
|
||||||
ctx.set('Content-Type', 'application/javascript');
|
return new Promise((resolve, reject) => {
|
||||||
if (process.env.NODE_ENV === 'production')
|
fs.readFile(src, { encoding: 'utf8' }, (err, data) => {
|
||||||
ctx.set('Cache-Control', `max-age=${30}`);
|
if (err) return reject(err);
|
||||||
await sendfile(ctx, path.join(__dirname, './static/service-worker.js'));
|
resolve(data);
|
||||||
if (!ctx.status) ctx.throw(httpErrors.NotFound());
|
});
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
router.get('/_health', ctx => (ctx.body = 'OK'));
|
router.get('/_health', ctx => (ctx.body = 'OK'));
|
||||||
|
|
||||||
@ -31,6 +32,13 @@ if (process.env.NODE_ENV === 'production') {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.get('/', async ctx => {
|
||||||
|
const html = await readFile(path.join(__dirname, '../dist/index.html'));
|
||||||
|
ctx.body = html;
|
||||||
|
|
||||||
|
if (!ctx.status) ctx.throw(httpErrors.NotFound());
|
||||||
|
});
|
||||||
|
|
||||||
router.get('*', async ctx => {
|
router.get('*', async ctx => {
|
||||||
await sendfile(ctx, path.join(__dirname, '../dist/index.html'));
|
await sendfile(ctx, path.join(__dirname, '../dist/index.html'));
|
||||||
if (!ctx.status) ctx.throw(httpErrors.NotFound());
|
if (!ctx.status) ctx.throw(httpErrors.NotFound());
|
||||||
@ -39,7 +47,10 @@ if (process.env.NODE_ENV === 'production') {
|
|||||||
koa.use(subdomainRedirect());
|
koa.use(subdomainRedirect());
|
||||||
} else {
|
} else {
|
||||||
router.get('*', async ctx => {
|
router.get('*', async ctx => {
|
||||||
await sendfile(ctx, path.join(__dirname, './static/dev.html'));
|
console.log(ctx.cookies.get('loggedIn'));
|
||||||
|
const html = await readFile(path.join(__dirname, './static/dev.html'));
|
||||||
|
ctx.body = html;
|
||||||
|
|
||||||
if (!ctx.status) ctx.throw(httpErrors.NotFound());
|
if (!ctx.status) ctx.throw(httpErrors.NotFound());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
26
yarn.lock
26
yarn.lock
@ -1041,12 +1041,12 @@ bcrypt-pbkdf@^1.0.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
tweetnacl "^0.14.3"
|
tweetnacl "^0.14.3"
|
||||||
|
|
||||||
bcrypt@^0.8.7:
|
bcrypt@1.0.3:
|
||||||
version "0.8.7"
|
version "1.0.3"
|
||||||
resolved "https://registry.yarnpkg.com/bcrypt/-/bcrypt-0.8.7.tgz#bc3875a9afd0a7b2cd231a6a7f218a5ce156b093"
|
resolved "https://registry.yarnpkg.com/bcrypt/-/bcrypt-1.0.3.tgz#b02ddc6c0b52ea16b8d3cf375d5a32e780dab548"
|
||||||
dependencies:
|
dependencies:
|
||||||
bindings "1.2.1"
|
nan "2.6.2"
|
||||||
nan "2.3.5"
|
node-pre-gyp "0.6.36"
|
||||||
|
|
||||||
beeper@^1.0.0:
|
beeper@^1.0.0:
|
||||||
version "1.1.1"
|
version "1.1.1"
|
||||||
@ -1067,10 +1067,6 @@ binary-extensions@^1.0.0:
|
|||||||
buffers "~0.1.1"
|
buffers "~0.1.1"
|
||||||
chainsaw "~0.1.0"
|
chainsaw "~0.1.0"
|
||||||
|
|
||||||
bindings@1.2.1:
|
|
||||||
version "1.2.1"
|
|
||||||
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.2.1.tgz#14ad6113812d2d37d72e67b4cacb4bb726505f11"
|
|
||||||
|
|
||||||
block-stream@*:
|
block-stream@*:
|
||||||
version "0.0.9"
|
version "0.0.9"
|
||||||
resolved "https://registry.yarnpkg.com/block-stream/-/block-stream-0.0.9.tgz#13ebfe778a03205cfe03751481ebb4b3300c126a"
|
resolved "https://registry.yarnpkg.com/block-stream/-/block-stream-0.0.9.tgz#13ebfe778a03205cfe03751481ebb4b3300c126a"
|
||||||
@ -4858,6 +4854,10 @@ js-beautify@^1.6.11:
|
|||||||
mkdirp "~0.5.0"
|
mkdirp "~0.5.0"
|
||||||
nopt "~3.0.1"
|
nopt "~3.0.1"
|
||||||
|
|
||||||
|
js-cookie@^2.1.4:
|
||||||
|
version "2.1.4"
|
||||||
|
resolved "https://registry.yarnpkg.com/js-cookie/-/js-cookie-2.1.4.tgz#da4ec503866f149d164cf25f579ef31015025d8d"
|
||||||
|
|
||||||
js-search@^1.4.2:
|
js-search@^1.4.2:
|
||||||
version "1.4.2"
|
version "1.4.2"
|
||||||
resolved "https://registry.yarnpkg.com/js-search/-/js-search-1.4.2.tgz#59a91e117d6badb20bf0d7643ba7577d5a81d7e2"
|
resolved "https://registry.yarnpkg.com/js-search/-/js-search-1.4.2.tgz#59a91e117d6badb20bf0d7643ba7577d5a81d7e2"
|
||||||
@ -6030,7 +6030,11 @@ mz@2:
|
|||||||
object-assign "^4.0.1"
|
object-assign "^4.0.1"
|
||||||
thenify-all "^1.0.0"
|
thenify-all "^1.0.0"
|
||||||
|
|
||||||
nan@2.3.5, nan@^2.3.0:
|
nan@2.6.2:
|
||||||
|
version "2.6.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/nan/-/nan-2.6.2.tgz#e4ff34e6c95fdfb5aecc08de6596f43605a7db45"
|
||||||
|
|
||||||
|
nan@^2.3.0:
|
||||||
version "2.3.5"
|
version "2.3.5"
|
||||||
resolved "https://registry.yarnpkg.com/nan/-/nan-2.3.5.tgz#822a0dc266290ce4cd3a12282ca3e7e364668a08"
|
resolved "https://registry.yarnpkg.com/nan/-/nan-2.3.5.tgz#822a0dc266290ce4cd3a12282ca3e7e364668a08"
|
||||||
|
|
||||||
@ -6185,7 +6189,7 @@ node-notifier@^5.0.2:
|
|||||||
shellwords "^0.1.0"
|
shellwords "^0.1.0"
|
||||||
which "^1.2.12"
|
which "^1.2.12"
|
||||||
|
|
||||||
node-pre-gyp@^0.6.36:
|
node-pre-gyp@0.6.36, node-pre-gyp@^0.6.36:
|
||||||
version "0.6.36"
|
version "0.6.36"
|
||||||
resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.6.36.tgz#db604112cb74e0d477554e9b505b17abddfab786"
|
resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.6.36.tgz#db604112cb74e0d477554e9b505b17abddfab786"
|
||||||
dependencies:
|
dependencies:
|
||||||
|
Reference in New Issue
Block a user