Skip to content

Commit 41982de

Browse files
committed
Added course layout.
1 parent 50228e3 commit 41982de

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { auth } from "@clerk/nextjs/server";
2+
import { redirect } from "next/navigation";
3+
4+
import { db } from "@/lib/db";
5+
6+
const CourseLayout = async ({
7+
children,
8+
params
9+
}: {
10+
children: React.ReactNode;
11+
params: { courseId: string };
12+
}) => {
13+
const { userId } = auth();
14+
15+
if (!userId){
16+
return redirect("/");
17+
}
18+
19+
const course = await db.course.findUnique({
20+
where: {
21+
id: params.courseId
22+
},
23+
include: {
24+
chapters: {
25+
where: {
26+
isPublished: true,
27+
},
28+
include: {
29+
userProgress: {
30+
where: {
31+
userId,
32+
},
33+
},
34+
},
35+
orderBy: {
36+
position: "asc",
37+
},
38+
},
39+
},
40+
});
41+
42+
return (
43+
<div>
44+
{children}
45+
</div>
46+
)
47+
}
48+
49+
export default CourseLayout

0 commit comments

Comments
 (0)