vigil/src/routes/logout/+page.server.ts

26 lines
595 B
TypeScript
Raw Normal View History

2025-09-12 19:20:30 +02:00
import { backend } from '$lib/backend.js';
import { getMe, setMe } from '$lib/globals.svelte.js';
import { error, redirect } from '@sveltejs/kit';
export async function load (event) {
const me = getMe();
const next = "/";
// already logged out
if (me == null) {
redirect(303, next);
}
const resp = await backend.withEvent(event).fetch("logout", {method: 'POST'});
if ([200, 204].indexOf(resp.status) >= 0) {
setMe(null);
redirect(303, next);
}
console.error(`status ${resp.status} received, not logging out`)
error(500);
}