Sharkey/src/server/api/common/signin.ts
2018-04-13 06:06:18 +09:00

20 lines
510 B
TypeScript

import * as Koa from 'koa';
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
ctx.cookies.set('i', user.token, {
path: '/',
domain: config.hostname,
secure: config.url.startsWith('https'),
httpOnly: false,
expires: new Date(Date.now() + expires),
maxAge: expires
});
if (redirect) {
ctx.redirect(config.url);
}
}