From 85e564448b0699828b4f7bb51232140ac3ac4303 Mon Sep 17 00:00:00 2001 From: William De Rocco <93288641+wderocco8@users.noreply.github.com> Date: Sat, 14 Sep 2024 11:58:54 -0400 Subject: [PATCH] added bu email validation to app form AND fixed another type isssue (auth-context doesn't need to extend sesh anymore) --- app/api/auth/[...nextauth]/route.ts | 2 -- app/contexts/AuthContext.tsx | 12 +----------- components/Form.tsx | 3 +++ 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts index 4dce29f..ad6988b 100644 --- a/app/api/auth/[...nextauth]/route.ts +++ b/app/api/auth/[...nextauth]/route.ts @@ -35,8 +35,6 @@ const client = new MongoClient(uri, { } }); - - async function isValidUser(email: string) { await client.connect(); const db = client.db("vault"); diff --git a/app/contexts/AuthContext.tsx b/app/contexts/AuthContext.tsx index e00daf5..50f7f16 100644 --- a/app/contexts/AuthContext.tsx +++ b/app/contexts/AuthContext.tsx @@ -6,22 +6,12 @@ import jwt from 'jsonwebtoken'; import { Session } from 'next-auth'; import { useRouter, usePathname } from 'next/navigation' - interface AuthContextProps { token: string | null; setToken: (token: string | null) => void; isLoading: boolean; } -interface CustomSession extends Session { - token?: { - isNewUser?: boolean; - _id?: string; - // Add other properties as needed - }; -} - - const AuthContext = createContext(undefined); export const AuthProvider: React.FC<{ children: ReactNode }> = ({ children }) => { @@ -34,7 +24,7 @@ export const AuthProvider: React.FC<{ children: ReactNode }> = ({ children }) => getSession().then((session: Session | null) => { if (session) { // Use type assertion to add the 'token' property - const sessionWithToken = session as CustomSession; + const sessionWithToken = session; // Check if user is a newUser if (sessionWithToken && sessionWithToken.token?.isNewUser === undefined || sessionWithToken.token?.isNewUser) { diff --git a/components/Form.tsx b/components/Form.tsx index de35dff..4cfe852 100644 --- a/components/Form.tsx +++ b/components/Form.tsx @@ -99,6 +99,9 @@ export default function Form({ title, listingId, questions, isPreview }: FormPro } else if (!confirmNotStudyingAbroad) { alert(`Sorry, you are ineligible to apply to Phi Chi Theta, Zeta Chapter. Please ensure that you are currently a BU undergraduate student and not studying abroad.`); return false; + } else if (!formData.email.endsWith("@bu.edu")) { + alert(`Please be sure to use you "@bu.edu" email.`) + return false; } return true; };