From b3eefc07a56ea934de126c0d039943edacffa95c Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 19 Aug 2022 23:13:01 -0700 Subject: get login and register working again --- src/lib/utils.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/lib/utils.js') diff --git a/src/lib/utils.js b/src/lib/utils.js index b42fe970..226002e7 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -1,3 +1,4 @@ +import cookie from 'cookie'; import { browser } from '$app/env'; import { toast } from '@zerodevx/svelte-toast'; @@ -96,3 +97,21 @@ export const info = (m) => { } }); }; + +export const login = async (user, setHeaders) => { + let maxAge = 30 * 24 * 60 * 60; + let { token } = await post('/login', user); + + let expires = new Date(); + expires.setSeconds(expires.getSeconds() + maxAge); + + setHeaders({ + 'set-cookie': cookie.serialize('token', token, { + httpOnly: true, + maxAge, + sameSite: 'lax', + path: '/', + expires + }) + }); +}; -- cgit v1.2.3