diff options
| author | Adam Soltys <[email protected]> | 2022-08-19 23:13:01 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-08-19 23:13:01 -0700 |
| commit | b3eefc07a56ea934de126c0d039943edacffa95c (patch) | |
| tree | 125cf73b09bb95eb0a79608f4ee5eaf1442b8e5f /src/lib/utils.js | |
| parent | e126a0ee16178f81c23934829d6d64eef7e8b7fb (diff) | |
| download | coinos-ui-b3eefc07a56ea934de126c0d039943edacffa95c.tar.gz coinos-ui-b3eefc07a56ea934de126c0d039943edacffa95c.zip | |
get login and register working again
Diffstat (limited to 'src/lib/utils.js')
| -rw-r--r-- | src/lib/utils.js | 19 |
1 files changed, 19 insertions, 0 deletions
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 + }) + }); +}; |
