summaryrefslogtreecommitdiff
path: root/src/server/api/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/api/common')
-rw-r--r--src/server/api/common/signin.ts29
1 files changed, 16 insertions, 13 deletions
diff --git a/src/server/api/common/signin.ts b/src/server/api/common/signin.ts
index 8d44b377fe..45a42e288d 100644
--- a/src/server/api/common/signin.ts
+++ b/src/server/api/common/signin.ts
@@ -4,21 +4,24 @@ import config from '../../../config';
import { ILocalUser } from '../../../models/user';
export default function(ctx: Koa.Context, user: ILocalUser, redirect = false) {
- const expires = 1000 * 60 * 60 * 24 * 365; // One Year
- ctx.cookies.set('i', user.token, {
- path: '/',
- domain: config.hostname,
- // SEE: https://github.com/koajs/koa/issues/974
- //secure: config.url.startsWith('https'),
- secure: false,
- httpOnly: false,
- expires: new Date(Date.now() + expires),
- maxAge: expires
- });
-
if (redirect) {
+ //#region Cookie
+ const expires = 1000 * 60 * 60 * 24 * 365; // One Year
+ ctx.cookies.set('i', user.token, {
+ path: '/',
+ domain: config.hostname,
+ // SEE: https://github.com/koajs/koa/issues/974
+ // When using a SSL proxy it should be configured to add the "X-Forwarded-Proto: https" header
+ secure: config.url.startsWith('https'),
+ httpOnly: false,
+ expires: new Date(Date.now() + expires),
+ maxAge: expires
+ });
+ //#endregion
+
ctx.redirect(config.url);
} else {
- ctx.status = 204;
+ ctx.body = { i: user.token };
+ ctx.status = 200;
}
}