You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/site/src/user.js

17 lines
503 B

import { writable } from 'svelte/store';
export const user = writable(null);
if (process.browser) {
// TODO this is a workaround for the fact that there's currently
// no way to pass session data from server to client
// TODO there is now! replace this with the session mechanism
fetch('/auth/me.json', { credentials: 'include' })
.then(r => r.json())
.then(user.set);
}
export async function logout() {
const r = await fetch(`/auth/logout`, { method: 'POST' });
if (r.ok) user.set(null);
}