Iterate, iterate
This commit is contained in:
@@ -3,18 +3,42 @@ import bodyParser from 'koa-bodyparser';
|
||||
import Koa from 'koa';
|
||||
import Router from 'koa-router';
|
||||
import validation from '../middlewares/validation';
|
||||
import auth from '../middlewares/authentication';
|
||||
import addMonths from 'date-fns/add_months';
|
||||
import { Team } from '../models';
|
||||
import { stripSubdomain } from '../../shared/utils/domains';
|
||||
|
||||
import slack from './slack';
|
||||
import google from './google';
|
||||
|
||||
const auth = new Koa();
|
||||
const app = new Koa();
|
||||
const router = new Router();
|
||||
|
||||
router.use('/', slack.routes());
|
||||
router.use('/', google.routes());
|
||||
|
||||
auth.use(bodyParser());
|
||||
auth.use(validation());
|
||||
auth.use(router.routes());
|
||||
router.get('/redirect', auth(), async ctx => {
|
||||
const user = ctx.state.user;
|
||||
|
||||
export default auth;
|
||||
// transfer cookie from root to subdomain specific
|
||||
ctx.cookies.set('accessToken', undefined, {
|
||||
httpOnly: true,
|
||||
domain: stripSubdomain(ctx.request.hostname),
|
||||
});
|
||||
|
||||
ctx.cookies.set('accessToken', user.getJwtToken(), {
|
||||
httpOnly: false,
|
||||
expires: addMonths(new Date(), 3),
|
||||
});
|
||||
|
||||
const team = await Team.findById(user.teamId);
|
||||
|
||||
console.log(`redirecting: ${team.url}/dashboard`);
|
||||
ctx.redirect(`${team.url}/dashboard`);
|
||||
});
|
||||
|
||||
app.use(bodyParser());
|
||||
app.use(validation());
|
||||
app.use(router.routes());
|
||||
|
||||
export default app;
|
||||
|
||||
Reference in New Issue
Block a user