aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes')
-rw-r--r--src/routes/__layout.svelte4
-rw-r--r--src/routes/login.js21
2 files changed, 24 insertions, 1 deletions
diff --git a/src/routes/__layout.svelte b/src/routes/__layout.svelte
index f5576edd..1af9679a 100644
--- a/src/routes/__layout.svelte
+++ b/src/routes/__layout.svelte
@@ -2,7 +2,11 @@
import '../app.css';
import { onMount } from 'svelte';
import { connect } from '$lib/socket';
+ import { token } from "$lib/store";
+ import { session } from "$app/stores";
+ import { browser } from "$app/env";
+ browser && ($token ||= $session.token);
onMount(connect);
</script>
diff --git a/src/routes/login.js b/src/routes/login.js
index 771de9e1..db1fbb6c 100644
--- a/src/routes/login.js
+++ b/src/routes/login.js
@@ -1,5 +1,24 @@
import { post } from '$lib/utils';
+import cookie from 'cookie';
+
+let maxAge = 30 * 24 * 60 * 60;
export async function POST({ request }) {
- return { body: await post('/login', await request.json()) };
+ let body = await post('/login', await request.json());
+
+ let expires = new Date();
+ expires.setSeconds(expires.getSeconds() + maxAge);
+
+ return {
+ body,
+ headers: {
+ 'set-cookie': cookie.serialize('token', body.token, {
+ httpOnly: true,
+ maxAge,
+ sameSite: 'lax',
+ path: '/',
+ expires
+ })
+ }
+ };
}