2018-04-12 21:06:18 +00:00
|
|
|
import * as Koa from 'koa';
|
|
|
|
|
2018-04-02 04:15:53 +00:00
|
|
|
import config from '../../../config';
|
2018-04-12 21:06:18 +00:00
|
|
|
import { ILocalUser } from '../../../models/user';
|
2017-11-23 04:25:33 +00:00
|
|
|
|
2018-04-12 21:06:18 +00:00
|
|
|
export default function(ctx: Koa.Context, user: ILocalUser, redirect: boolean) {
|
2017-11-23 04:25:33 +00:00
|
|
|
const expires = 1000 * 60 * 60 * 24 * 365; // One Year
|
2018-04-12 21:06:18 +00:00
|
|
|
ctx.cookies.set('i', user.token, {
|
2017-11-23 04:25:33 +00:00
|
|
|
path: '/',
|
2018-04-12 21:06:18 +00:00
|
|
|
domain: config.hostname,
|
|
|
|
secure: config.url.startsWith('https'),
|
2017-11-23 04:25:33 +00:00
|
|
|
httpOnly: false,
|
|
|
|
expires: new Date(Date.now() + expires),
|
|
|
|
maxAge: expires
|
|
|
|
});
|
|
|
|
|
|
|
|
if (redirect) {
|
2018-04-12 21:06:18 +00:00
|
|
|
ctx.redirect(config.url);
|
2017-11-23 04:25:33 +00:00
|
|
|
}
|
|
|
|
}
|