aboutsummaryrefslogtreecommitdiff
path: root/src/routes/logout.ts
blob: 9caebb62d97b22cd0d3fe8500dfa61d2ec5f1704 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { API_URL } from '$lib/api'
import type { RequestHandler } from '@sveltejs/kit'

export const get: RequestHandler = async ({ locals, url }) => {
	// if the sid is wrong, nothing to do
	if (url.searchParams.has('sid') && url.searchParams.get('sid') === locals.sid) {
		await fetch(`${API_URL}accounts/session`, {
			method: 'DELETE',
			headers: {
				'Content-Type': 'application/json',
			},
			body: JSON.stringify({
				uuid: locals.sid
			}),
		}).then(res => {
			if (res.status !== 200)
				throw new Error(res.statusText)
		})
	}
	return {
		status: 303,
		headers: {
			location: '/',
			'Set-Cookie': 'sid=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/;'
		}
	}

}