Portfolio/frontend/src/routes/(candidate)/(authenticated)/+layout.server.ts
2023-01-03 15:11:21 +01:00

19 lines
472 B
TypeScript

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