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

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