diff options
| author | Adam Soltys <[email protected]> | 2022-10-03 10:21:24 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-10-03 10:21:24 -0700 |
| commit | 1792eb0ce5a2ff127e9f3c3bce392749f20b3f86 (patch) | |
| tree | ebae8e1984d66cac88f04177fcad1a279313aa8c /src/lib | |
| parent | cb272477247582355d38bc6c47b1795801689a55 (diff) | |
| download | coinos-ui-1792eb0ce5a2ff127e9f3c3bce392749f20b3f86.tar.gz coinos-ui-1792eb0ce5a2ff127e9f3c3bce392749f20b3f86.zip | |
migrate to new actions/cookies api
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/utils.js | 18 |
1 files changed, 3 insertions, 15 deletions
diff --git a/src/lib/utils.js b/src/lib/utils.js index f2c7a6a4..a7d0adaa 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -1,4 +1,3 @@ -import cookie from 'cookie'; import { browser } from '$app/environment'; import { toast } from '@zerodevx/svelte-toast'; import { goto } from '$app/navigation'; @@ -107,28 +106,17 @@ export const info = (m) => { }); }; -export const login = async (user, setHeaders) => { +export const login = async (user, cookies) => { 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 - }) - }); + cookies.set('token', token, { path: '/' }); }; -export const auth = (req) => { - let { token } = cookie.parse(req.headers.get('cookie') || ''); - return { authorization: `Bearer ${token}` }; -}; +export const auth = (cookies) => ({ authorization: `Bearer ${cookies.get('token')}` }); export const f = (s, currency) => new Intl.NumberFormat('en-US', { |
