Skip to content

Commit

Permalink
added bu email validation to app form AND fixed another type isssue (…
Browse files Browse the repository at this point in the history
…auth-context doesn't need to extend sesh anymore)
  • Loading branch information
wderocco8 committed Sep 14, 2024
1 parent d9478b5 commit 85e5644
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 13 deletions.
2 changes: 0 additions & 2 deletions app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ const client = new MongoClient(uri, {
}
});



async function isValidUser(email: string) {
await client.connect();
const db = client.db("vault");
Expand Down
12 changes: 1 addition & 11 deletions app/contexts/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<AuthContextProps | undefined>(undefined);

export const AuthProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
Expand All @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit 85e5644

Please sign in to comment.