chefbible/src/routes/recipe/[id]/edit/+page.server.ts

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
};
};