From 925ad2bfff17f8d9381731fb0050936dcd7e0a72 Mon Sep 17 00:00:00 2001 From: mat Date: Thu, 15 Dec 2022 18:14:46 -0600 Subject: finish migrating to sveltekit v1 hopefully --- src/routes/logout/+server.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/routes/logout/+server.ts (limited to 'src/routes/logout/+server.ts') diff --git a/src/routes/logout/+server.ts b/src/routes/logout/+server.ts new file mode 100644 index 0000000..2e0f40d --- /dev/null +++ b/src/routes/logout/+server.ts @@ -0,0 +1,23 @@ +import { fetchApi } from '$lib/api' +import { redirect, type RequestHandler } from '@sveltejs/kit' + +export const GET = (async ({ url, cookies, locals }) => { + // if the sid is wrong, nothing to do + if (url.searchParams.has('sid') && url.searchParams.get('sid') === locals.sid) { + await fetchApi(`accounts/session`, fetch, { + method: 'DELETE', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + uuid: locals.sid + }), + }).then(res => { + if (res.status !== 200) + throw new Error(res.statusText) + }) + } + + cookies.delete('sid') + throw redirect(303, '/') +}) as RequestHandler -- cgit