From 767a292dbdaedeb34de5476f0c23ca25a0395e90 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 23 Nov 2017 13:25:33 +0900 Subject: #939 --- src/api/common/signin.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/api/common/signin.ts (limited to 'src/api/common') diff --git a/src/api/common/signin.ts b/src/api/common/signin.ts new file mode 100644 index 0000000000..693e62f39f --- /dev/null +++ b/src/api/common/signin.ts @@ -0,0 +1,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); + } +} -- cgit v1.2.3-freya