diff options
author | mat <27899617+mat-1@users.noreply.github.com> | 2022-12-15 20:19:42 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-15 20:19:42 -0600 |
commit | ed5eedab8f9fc90dadf5c442cf559572d1b35f0c (patch) | |
tree | 01a763fd11810e9970f14f7dae180e95b279de9a /src/routes/logout/+server.ts | |
parent | 89bf3d31e36ad3bdfd45461ee6fb69a4c791f848 (diff) | |
parent | 103689520f51991a1e9a4ca5829fe2f46d1a32c2 (diff) | |
download | skyblock-stats-ed5eedab8f9fc90dadf5c442cf559572d1b35f0c.tar.gz skyblock-stats-ed5eedab8f9fc90dadf5c442cf559572d1b35f0c.tar.bz2 skyblock-stats-ed5eedab8f9fc90dadf5c442cf559572d1b35f0c.zip |
Merge pull request #6 from skyblockstats/sveltekit-v1
Sveltekit v1
Diffstat (limited to 'src/routes/logout/+server.ts')
-rw-r--r-- | src/routes/logout/+server.ts | 23 |
1 files changed, 23 insertions, 0 deletions
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 |