27 lines
No EOL
629 B
TypeScript
27 lines
No EOL
629 B
TypeScript
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);
|
|
}
|
|
|
|
// cookies managed by backend
|
|
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);
|
|
} |