summaryrefslogtreecommitdiff
path: root/src/api/common/signin.ts
blob: 693e62f39fcdbddcdf3ce71a5069ea6480d96a17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import config from '../../conf';

export default function(res, user, redirect: boolean) {
	const expires = 1000 * 60 * 60 * 24 * 365; // One Year
	res.cookie('i', user.token, {
		path: '/',
		domain: `.${config.host}`,
		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);
	}
}