feat: add auto logout

This commit is contained in:
EETagent 2023-01-12 13:19:17 +01:00
parent f4080f75b7
commit 87c35107ce

View file

@ -1,10 +1,19 @@
import type { LayoutServerLoad } from './$types';
import { redirect } from '@sveltejs/kit';
import { apiWhoami } from '$lib/@api/admin';
export const load: LayoutServerLoad = ({ cookies }) => {
export const load: LayoutServerLoad = async ({ cookies, fetch }) => {
const isAuthenticated = cookies.get('id');
if (!isAuthenticated) {
throw redirect(302, '/admin/auth/login');
if (isAuthenticated) {
const whoami = await apiWhoami(fetch).catch((e) => {
throw redirect(302, '/admin/auth/logout');
});
return {
whoami: whoami
};
} else {
throw redirect(302, '/admin/auth/logout');
}
};