mirror of
https://github.com/taogaetz/chefbible.git
synced 2025-12-06 19:50:12 -05:00
31 lines
713 B
TypeScript
31 lines
713 B
TypeScript
import type { PageServerLoad } from './$types';
|
|
import prisma from '$lib/server/prisma';
|
|
import { redirect } from '@sveltejs/kit';
|
|
|
|
export const load: PageServerLoad = async ({ params, locals }) => {
|
|
// Check if user is authenticated
|
|
if (!locals.authenticated) {
|
|
throw redirect(302, '/');
|
|
}
|
|
|
|
const recipe = await prisma.recipe.findUnique({
|
|
where: { id: params.id },
|
|
include: {
|
|
ingredients: {
|
|
include: {
|
|
ingredient: true
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
if (!recipe) {
|
|
throw new Error('Recipe not found');
|
|
}
|
|
|
|
return {
|
|
recipe,
|
|
authenticated: locals.authenticated
|
|
};
|
|
};
|