diff --git a/.env b/.env index 72b464a3..d4b24e98 100644 --- a/.env +++ b/.env @@ -1,4 +1,3 @@ NEXT_PUBLIC_SUPABASE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.ewogICJyb2xlIjogImFub24iLAogICJpc3MiOiAic3VwYWJhc2UiLAogICJpYXQiOiAxNjk1Mzk4NDAwLAogICJleHAiOiAxODUzMjUxMjAwCn0.IldZY_FwoLs6cXpVyas9fR_F3uLDWSXu70s3Uyvn-dI NEXT_PUBLIC_SUPABASE_URL=https://sb.chibimello.com/ -NEXTAUTH_URL=https://nthumods.com NTHU_OAUTH_CLIENT_ID=nthumods \ No newline at end of file diff --git a/.env.development b/.env.development new file mode 100644 index 00000000..00fb1f38 --- /dev/null +++ b/.env.development @@ -0,0 +1 @@ +NEXTAUTH_URL=http://localhost:3000 \ No newline at end of file diff --git a/.env.production b/.env.production new file mode 100644 index 00000000..5a1e129c --- /dev/null +++ b/.env.production @@ -0,0 +1 @@ +NEXTAUTH_URL=https://nthumods.com \ No newline at end of file diff --git a/src/app/[lang]/cds/CdsCourseForm.tsx b/src/app/[lang]/cds/CdsCourseForm.tsx index 142e0b64..2e399078 100644 --- a/src/app/[lang]/cds/CdsCourseForm.tsx +++ b/src/app/[lang]/cds/CdsCourseForm.tsx @@ -34,6 +34,7 @@ import { normalizeRoomName } from '@/const/venues'; import { useMediaQuery } from 'usehooks-ts'; import { useSettings } from '@/hooks/contexts/settings'; import supabase, { CdsCourseDefinition } from '@/config/supabase'; +import { useSession } from 'next-auth/react'; const createTimetableFromCdsCourses = (data: CdsCourseDefinition[], theme = 'tsinghuarian') => { const newTimetableData: CourseTimeslotData[] = []; @@ -92,6 +93,10 @@ const CdsCoursesForm: FC<{ const { timetableTheme } = useSettings(); const [displayToggles, setDisplayToggles] = useState<{ [key: string]: boolean }>({}); const scrollRef = useRef(null); + + const session = useSession(); + console.log(session) + const emptyFilters = { textSearch: "", level: [1, 2, 3, 4], diff --git a/src/app/api/auth/[...nextauth]/route.ts b/src/app/api/auth/[...nextauth]/route.ts index 57219b4b..27329c74 100644 --- a/src/app/api/auth/[...nextauth]/route.ts +++ b/src/app/api/auth/[...nextauth]/route.ts @@ -1,44 +1,78 @@ import NextAuth from "next-auth" +import CredentialsProvider from "next-auth/providers/credentials" const handler = NextAuth({ - providers: [ - { - id: "nthu", - name: "NTHU", - type: "oauth", - clientId: process.env.NTHU_OAUTH_CLIENT_ID, - clientSecret: process.env.NTHU_OAUTH_SECRET_KEY, - authorization: { - url: "https://oauth.ccxp.nthu.edu.tw/v1.1/authorize.php", - params: { scope: "inschool email userid name" } - }, - token: "https://oauth.nthumods.com/v1.1/token.php", - userinfo: "https://oauth.nthumods.com/v1.1/resource.php", - profile(profile) { - if(profile.success == false) throw new Error("Failed to fetch user profile"); - return { - id: profile.userid, - inschool: profile.inschool, - name_zh: profile.name, - name_en: profile.name_en, - email: profile.email, - } - }, + session: { strategy: "jwt" }, + providers: [ + process.env.NODE_ENV === "development" + ? CredentialsProvider({ + id: "dev", + name: "Credentials", + credentials: { + username: { + label: "Username", + type: "text", + placeholder: "jsmith", + }, + password: { label: "Password", type: "password" }, + }, + async authorize() { + return { + id: "b07901001", + inschool: true, + name: "王小明", + name_en: "Wang, Xiao-Ming", + email: "chewtzihwee@gmail.com" } - ], - callbacks: { - async jwt({ token, account, profile }) { - // Persist the OAuth access_token and or the user id to the token right after signin - if (account && profile) { - token.id = profile.id, - token.name = profile.name_zh, - token.name_en = profile.name_en, - token.inschool = profile.inschool, - token.email = profile.email + }, + }) + : { + id: "nthu", + name: "NTHU", + type: "oauth", + clientId: process.env.NTHU_OAUTH_CLIENT_ID, + clientSecret: process.env.NTHU_OAUTH_SECRET_KEY, + authorization: { + url: "https://oauth.ccxp.nthu.edu.tw/v1.1/authorize.php", + params: { scope: "inschool email userid name" } + }, + token: "https://oauth.nthumods.com/v1.1/token.php", + userinfo: "https://oauth.nthumods.com/v1.1/resource.php", + profile(profile, tokens) { + if (profile.success == false) throw new Error("Failed to fetch user profile"); + return { + id: profile.userid, + inschool: profile.inschool, + name_zh: profile.name, + name_en: profile.name_en, + email: profile.email, + } + }, + } + ], + callbacks: { + async jwt({ token, account, profile }) { + if (process.env.NODE_ENV == 'development') { + return { + ...token, + id: "b07901001", + inschool: true, + name_zh: "王小明", + name_en: "Wang, Xiao-Ming", + email: "chewtzihwee@gmail.com" } - return token - } + } + + if (account && profile) { + token.id = profile.id, + token.name = profile.name_zh, + token.name_en = profile.name_en, + token.inschool = profile.inschool, + token.email = profile.email + } + return token } + } }) export { handler as GET, handler as POST }