export const dynamic = 'force-dynamic'; import { getTeacherCourses } from "./actions"; // Import the server action import Link from "next/link"; import { redirect } from "next/navigation"; import { requireTeacher } from "@/lib/auth/requireTeacher"; import { logger } from "@/lib/logger"; export default async function TeacherDashboardPage() { try { // 1. Auth Check (Double protection) // We log the attempt logger.info("Accessing Teacher Dashboard"); // We wrap requireTeacher to catch potential DB/Supabase connection errors let user; try { user = await requireTeacher(); } catch (authError) { logger.error("requireTeacher failed with exception", authError); throw authError; } if (!user) { logger.info("User not authorized as teacher, redirecting"); redirect("/auth/login?role=teacher"); } // 2. Fetch Data const { success, data: courses, error } = await getTeacherCourses(); return (
{/* Header */}

Panel del Profesor

Gestiona tus cursos y contenidos.

+ Nuevo Curso
{/* Error State */} {!success && (
Error: {error}
)} {/* List State */} {success && courses && (
{courses.length === 0 ? ( // Empty State

No hay cursos

Empieza creando tu primer curso de Inglés Jurídico.

) : ( // Course Cards courses.map((course) => (
{course.status === 'PUBLISHED' ? 'Publicado' : 'Borrador'} ${course.price.toString()}

{course.title as string}

{course.level}

📚 {course._count.modules} Módulos 👥 {course._count.enrollments} Alumnos
)) )}
)}
); } catch (error) { logger.error("Critical error in TeacherDashboardPage", error); throw error; } }