From 9216f6e285afbaf67da18159472023930ef6c5bf Mon Sep 17 00:00:00 2001 From: cfngc4594 Date: Sat, 21 Jun 2025 00:35:20 +0800 Subject: [PATCH] feat(problems): add published check in problem layout --- src/app/(app)/problems/[problemId]/layout.tsx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/app/(app)/problems/[problemId]/layout.tsx b/src/app/(app)/problems/[problemId]/layout.tsx index fe22fac..72db5c0 100644 --- a/src/app/(app)/problems/[problemId]/layout.tsx +++ b/src/app/(app)/problems/[problemId]/layout.tsx @@ -1,3 +1,4 @@ +import prisma from "@/lib/prisma"; import { notFound } from "next/navigation"; import { ProblemHeader } from "@/features/problems/components/header"; @@ -13,6 +14,19 @@ const Layout = async ({ children, params }: LayoutProps) => { return notFound(); } + const problem = await prisma.problem.findUnique({ + select: { + isPublished: true, + }, + where: { + id: problemId, + }, + }); + + if (!problem?.isPublished) { + return notFound(); + } + return (