From 1792eb0ce5a2ff127e9f3c3bce392749f20b3f86 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 3 Oct 2022 10:21:24 -0700 Subject: migrate to new actions/cookies api --- src/lib/utils.js | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'src/lib') 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', { -- cgit v1.2.3