diff --git a/src/components/Course/CourseView.tsx b/src/components/Course/CourseView.tsx index fc0d188c9..1b3b23931 100644 --- a/src/components/Course/CourseView.tsx +++ b/src/components/Course/CourseView.tsx @@ -1,4 +1,4 @@ -import { lazy, type ReactNode } from 'react'; +import { lazy, useEffect, useState, type ReactNode } from 'react'; import type { LessonFileType } from '../../lib/course'; import { CourseLayout, type CourseLayoutProps } from './CourseLayout'; import { @@ -6,6 +6,9 @@ import { ResizablePanel, ResizablePanelGroup, } from '../Resizable'; +import { isLoggedIn } from '../../lib/jwt'; +import { IdCardIcon, Loader2Icon } from 'lucide-react'; +import { showLoginPopup } from '../../lib/popup'; const SqlCodeEditor = lazy(() => import('../SqlCodeEditor/SqlCodeEditor').then((module) => ({ @@ -38,6 +41,45 @@ export function CourseView(props: CourseViewProps) { 'lesson-quiz', ].includes(lessonType); + const [isLoading, setIsLoading] = useState(true); + const isAuthenticated = isLoggedIn(); + + useEffect(() => { + if (isAuthenticated === undefined) { + return; + } + + setIsLoading(false); + }, [isAuthenticated]); + + if (isLoading) { + return ( +
+ +
+ ); + } + + if (!isAuthenticated) { + return ( +
+ +

+ You need to be logged in to access this course. +

+ + +
+ ); + } + return ( @@ -49,10 +91,10 @@ export function CourseView(props: CourseViewProps) {
-

+

{lesson.frontmatter.title}

-
+
{children}