hippofish/src/server/api/common/signin.ts

20 lines
452 B
TypeScript
Raw Normal View History

2018-04-02 06:15:53 +02:00
import config from '../../../config';
2017-11-23 05:25:33 +01:00
export default function(res, user, redirect: boolean) {
const expires = 1000 * 60 * 60 * 24 * 365; // One Year
res.cookie('i', user.account.token, {
2017-11-23 05:25:33 +01:00
path: '/',
2018-03-26 06:21:41 +02:00
domain: `.${config.hostname}`,
2017-11-23 05:25:33 +01:00
secure: config.url.substr(0, 5) === 'https',
httpOnly: false,
expires: new Date(Date.now() + expires),
maxAge: expires
});
if (redirect) {
res.redirect(config.url);
} else {
res.sendStatus(204);
}
}