import type { Handle } from '@sveltejs/kit';
import { KRATOS_SESSION_COOKIE } from '$lib/config';

export const handle: Handle = async ({ event, resolve }) => {
	// Extract Kratos session cookie for forwarding to backend
	const cookie = event.cookies.get(KRATOS_SESSION_COOKIE);
	event.locals.cookie = cookie ? `${KRATOS_SESSION_COOKIE}=${cookie}` : null;

	return resolve(event);
};
