diff --git a/src/app/[lang]/cds/CdsCourseForm.tsx b/src/app/[lang]/cds/CdsCourseForm.tsx
index 37a56ce6..142e0b64 100644
--- a/src/app/[lang]/cds/CdsCourseForm.tsx
+++ b/src/app/[lang]/cds/CdsCourseForm.tsx
@@ -1,3 +1,4 @@
+'use client';
import Timetable from '@/components/Timetable/Timetable';
import { FC, Fragment, useState, useRef, useEffect, useMemo } from 'react';
import { scheduleTimeSlots } from '@/const/timetable';
diff --git a/src/app/[lang]/cds/CdsFormContainer.tsx b/src/app/[lang]/cds/CdsFormContainer.tsx
index 864ac34d..8057b1fd 100644
--- a/src/app/[lang]/cds/CdsFormContainer.tsx
+++ b/src/app/[lang]/cds/CdsFormContainer.tsx
@@ -2,19 +2,24 @@ import {CircularProgress} from '@mui/joy';
import useSWR from 'swr';
import CdsCoursesForm from './CdsCourseForm';
import supabase from '@/config/supabase';
+import { getServerSession } from 'next-auth';
+import { redirect } from 'next/navigation';
-const CdsFormContainer = () => {
- //assuming preferences is a string of raw_id
+const getUserPreferences = async () => {
+ const session = await getServerSession();
+ if(session == null || !session.user) return redirect('/');
const preferences: string[] = [];
- const { data: preferenceCourses = [], error, isLoading } = useSWR(['cds_courses'], async () => {
- const { data = [], error } = await supabase.from('cds_courses').select('*').in('raw_id', preferences);
- if(error) throw error;
- return data ?? [];
- })
+ //get user preferences
+ const { data: preferenceCourses = [], error } = await supabase.from('cds_courses').select('*').in('raw_id', preferences);
+ if(error) throw error;
+ return preferenceCourses ?? [];
+}
+
+const CdsFormContainer = async () => {
+ const preferenceCourses = await getUserPreferences();
- if(isLoading) return
return (
)
diff --git a/src/app/[lang]/cds/NTHULoginButton.tsx b/src/app/[lang]/cds/NTHULoginButton.tsx
new file mode 100644
index 00000000..acfbe85d
--- /dev/null
+++ b/src/app/[lang]/cds/NTHULoginButton.tsx
@@ -0,0 +1,13 @@
+'use client';
+import NTHUBirdIcon from '@/components/NTHUBirdIcon';
+import { Button } from '@mui/joy';
+import { signIn } from 'next-auth/react';
+import { FC } from 'react';
+
+const NTHULoginButton: FC = () => {
+ return
+ } variant="outlined" color="neutral" onClick={() => signIn('nthu')}>Login with NTHU
+
+}
+
+export default NTHULoginButton;
\ No newline at end of file
diff --git a/src/app/[lang]/cds/page.tsx b/src/app/[lang]/cds/page.tsx
index 5f3e107a..142b2f83 100644
--- a/src/app/[lang]/cds/page.tsx
+++ b/src/app/[lang]/cds/page.tsx
@@ -1,27 +1,20 @@
-'use client';;
import NTHUBirdIcon from "@/components/NTHUBirdIcon"
import { Alert, Button, Divider } from "@mui/joy";
import { signIn, useSession } from "next-auth/react"
import { FC } from "react";
import CdsFormContainer from "./CdsFormContainer";
-import { useSettings } from "@/hooks/contexts/settings";
+import { cookies } from "next/headers";
+import {getServerSession} from 'next-auth';
+import NTHULoginButton from "./NTHULoginButton";
-const CdsFormBeforeSignIn: FC<{ isLoggingIn: boolean }> = ({ isLoggingIn }) => {
- return
- } variant="outlined" color="neutral" onClick={() => signIn('nthu')}>Login with NTHU
-
-}
-
-const CourseDemandSurvey = () => {
- const { data, status, update } = useSession();
- const { darkMode } = useSettings();
-
- console.log(data, status);
-
-
- // if(true) return
+const CourseDemandSurvey = async () => {
+ const cookieStore = cookies()
+ const theme = cookieStore.get('theme');
+ const darkMode = theme?.value == 'dark';
+ const session = await getServerSession();
- return
+ if(session) return
+ else return
選課意願調查
@@ -36,9 +29,9 @@ const CourseDemandSurvey = () => {
開放時間:2021/10/18 00:00 ~ 2021/10/24 23:59
-
+
-
+ {/*
*/}
}
diff --git a/src/middleware.ts b/src/middleware.ts
index 20e5f0fe..6ab5f61a 100644
--- a/src/middleware.ts
+++ b/src/middleware.ts
@@ -13,7 +13,7 @@ function getLocale(request: NextRequest) {
return match(languages, locales, defaultLocale)
}
-
+
export function middleware(request: NextRequest) {
// Check if there is any supported locale in the pathname
const { pathname } = request.nextUrl