diff options
Diffstat (limited to 'src/routes/login.js')
| -rw-r--r-- | src/routes/login.js | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/routes/login.js b/src/routes/login.js index e8c74365..db1fbb6c 100644 --- a/src/routes/login.js +++ b/src/routes/login.js @@ -1,13 +1,24 @@ -import got from 'got'; +import { post } from '$lib/utils'; +import cookie from 'cookie'; + +let maxAge = 30 * 24 * 60 * 60; export async function POST({ request }) { - let json = await request.json(); + let body = await post('/login', await request.json()); - let body = await got - .post('http://localhost:3119/login', { - json - }) - .json(); + let expires = new Date(); + expires.setSeconds(expires.getSeconds() + maxAge); - return { body }; + return { + body, + headers: { + 'set-cookie': cookie.serialize('token', body.token, { + httpOnly: true, + maxAge, + sameSite: 'lax', + path: '/', + expires + }) + } + }; } |
