aboutsummaryrefslogtreecommitdiff
path: root/src/routes/logout/+server.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes/logout/+server.ts')
-rw-r--r--src/routes/logout/+server.ts23
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