import { kratosServerClient } from '$lib/kratos-server';
import type { PageServerLoad } from './$types';

export const load: PageServerLoad = async ({ url }) => {
	const flowId = url.searchParams.get('id');

	if (!flowId) {
		return {
			errorMessage: 'An error occurred. Please try again.'
		};
	}

	try {
		const { data: flow } = await kratosServerClient.getFlowError({ id: flowId });
		return { flow };
	} catch (error) {
		console.error('Error flow error:', error);
		return {
			errorMessage: 'An error occurred. Please try again.'
		};
	}
};
