Portfolio/frontend/src/routes/(admin)/admin/(authenticated)/+layout.server.ts
2023-01-12 13:31:31 +01:00

19 lines
479 B
TypeScript

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