Allow admin to preview unpublished lessons without enrollment
- Course layout skips enrollment and published checks for admin role - Lesson page skips published filter for admin role - Enables admin preview button to work for any lesson/course state Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { notFound } from "next/navigation";
|
||||
import Link from "next/link";
|
||||
import { headers } from "next/headers";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { KinescopePlayer } from "@/components/player/kinescope-player";
|
||||
import { LessonContent } from "@/components/student/lesson-content";
|
||||
|
||||
@@ -11,8 +13,11 @@ interface Props {
|
||||
export default async function LessonPage({ params }: Props) {
|
||||
const { slug, lessonId } = await params;
|
||||
|
||||
const session = await auth.api.getSession({ headers: await headers() });
|
||||
const isAdmin = session?.user.role === "admin";
|
||||
|
||||
const lesson = await prisma.lesson.findUnique({
|
||||
where: { id: lessonId, published: true },
|
||||
where: { id: lessonId, ...(isAdmin ? {} : { published: true }) },
|
||||
include: {
|
||||
files: { orderBy: { createdAt: "asc" } },
|
||||
module: {
|
||||
|
||||
Reference in New Issue
Block a user