This commit is contained in:
syuilo
2018-04-13 06:06:18 +09:00
parent a3bd4ba426
commit 3368fe8552
20 changed files with 582 additions and 609 deletions

View File

@ -1,19 +1,20 @@
import config from '../../../config';
import * as Koa from 'koa';
export default function(res, user, redirect: boolean) {
import config from '../../../config';
import { ILocalUser } from '../../../models/user';
export default function(ctx: Koa.Context, user: ILocalUser, redirect: boolean) {
const expires = 1000 * 60 * 60 * 24 * 365; // One Year
res.cookie('i', user.token, {
ctx.cookies.set('i', user.token, {
path: '/',
domain: `.${config.hostname}`,
secure: config.url.substr(0, 5) === 'https',
domain: config.hostname,
secure: config.url.startsWith('https'),
httpOnly: false,
expires: new Date(Date.now() + expires),
maxAge: expires
});
if (redirect) {
res.redirect(config.url);
} else {
res.sendStatus(204);
ctx.redirect(config.url);
}
}