import { db } from "@/lib/prisma"; import { requireTeacher } from "@/lib/auth/requireTeacher"; import { redirect, notFound } from "next/navigation"; import Link from "next/link"; import { LessonEditorForm } from "./LessonEditorForm"; function getText(value: unknown): string { if (!value) return ""; if (typeof value === "string") return value; if (typeof value === "object") { const text = value as Record; return text.es || text.en || ""; } return ""; } interface PageProps { params: Promise<{ slug: string; lessonId: string }>; } export default async function LessonPage({ params }: PageProps) { const user = await requireTeacher(); if (!user) redirect("/auth/login"); const { slug, lessonId } = await params; // 1. Fetch Lesson + Course Info (for breadcrumbs) const lesson = await db.lesson.findUnique({ where: { id: lessonId }, include: { module: { include: { course: { select: { title: true, slug: true, authorId: true } } } } } }); // 2. Security & Null Checks if (!lesson) notFound(); if (lesson.module.course.authorId !== user.id) redirect("/teacher"); return (
{/* Breadcrumbs */}
Cursos / {getText(lesson.module.course.title)} / {getText(lesson.title)}

Editar Lección

{/* The Client Form */}
); }