Request auth on first load with existing token

This commit is contained in:
Tom Moor
2017-11-26 22:26:02 -08:00
parent bd8829d057
commit a573c76512
5 changed files with 50 additions and 15 deletions

View File

@ -1,11 +1,24 @@
// @flow
import Router from 'koa-router';
import auth from './middlewares/authentication';
import { presentUser, presentTeam } from '../presenters';
import { User, Team } from '../models';
import * as Slack from '../slack';
const router = new Router();
router.post('auth.info', auth(), async ctx => {
const user = ctx.state.user;
const team = await Team.findOne({ where: { id: user.teamId } });
ctx.body = {
data: {
user: await presentUser(ctx, user),
team: await presentTeam(ctx, team),
},
};
});
router.post('auth.slack', async ctx => {
const { code } = ctx.body;
ctx.assertPresent(code, 'code is required');