File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed
app/(course)/courses/[courseId] Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments