From 2de09a0183875af6434555b4c1d0b8b910047874 Mon Sep 17 00:00:00 2001 From: clarayin129 Date: Sun, 7 Sep 2025 18:10:35 -0700 Subject: [PATCH 1/7] Add signIn on client and callback --- .../_components/AuthForms/LoginForm.tsx | 21 +++++++++++++ auth.ts | 31 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/app/(pages)/(hackers)/_components/AuthForms/LoginForm.tsx b/app/(pages)/(hackers)/_components/AuthForms/LoginForm.tsx index 75b0ee726..c3ebe258e 100644 --- a/app/(pages)/(hackers)/_components/AuthForms/LoginForm.tsx +++ b/app/(pages)/(hackers)/_components/AuthForms/LoginForm.tsx @@ -4,6 +4,7 @@ import { useRouter } from 'next/navigation'; import LoginAction from '@actions/auth/login'; import AuthForm from '@components/AuthForm/AuthForm'; +import { signIn } from 'next-auth/react'; export default function LoginForm() { const router = useRouter(); @@ -33,7 +34,12 @@ export default function LoginForm() { }, ]; + const handleGoogleLogin = async () => { + await signIn('google', { callbackUrl: '/' }); + }; + return ( +
+ +
); } diff --git a/auth.ts b/auth.ts index 6839c29b7..44c85a85c 100644 --- a/auth.ts +++ b/auth.ts @@ -1,4 +1,5 @@ import NextAuth, { DefaultSession } from 'next-auth'; +import GoogleProvider from 'next-auth/providers/google'; import 'next-auth/jwt'; import Credentials from 'next-auth/providers/credentials'; import { compare } from 'bcryptjs'; @@ -79,6 +80,18 @@ export const { auth, handlers, signIn, signOut } = NextAuth({ } }, }), + GoogleProvider({ + clientId: process.env.GOOGLE_CLIENT_ID, + clientSecret: process.env.GOOGLE_CLIENT_SECRET, + authorization: { + params: { + prompt: 'consent', + access_type: 'offline', + response_type: 'code', + scope: 'openid email profile', + }, + }, + }), ], callbacks: { async jwt({ token, user }) { @@ -95,6 +108,24 @@ export const { auth, handlers, signIn, signOut } = NextAuth({ session.user.role = token.role; return session; }, + async signIn({ account, profile }) { + if (!account || !profile?.email) { + console.log('[NextAuth] Missing account or profile', { account, profile }); + return false; + } + if (account?.provider === 'google' && profile?.email) { + const response = await GetManyUsers({ email: profile.email }); + if (!response.ok || response.body.length === 0) { + console.log(`[NextAuth] Google login denied, user not found: ${profile.email}`); + return false; // Deny sign-in if user not in DB + } + + console.log(`[NextAuth] Google login allowed for: ${profile.email}`); + return true; + } + + return true; // allow sign-in + }, }, secret: process.env.AUTH_SECRET, }); From cf246739baff8add190367a7867e47b0a5614a58 Mon Sep 17 00:00:00 2001 From: clarayin129 Date: Sun, 7 Sep 2025 18:21:57 -0700 Subject: [PATCH 2/7] Fix prettier problems --- .../_components/AuthForms/LoginForm.tsx | 28 +++++++++---------- auth.ts | 13 ++++++--- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/app/(pages)/(hackers)/_components/AuthForms/LoginForm.tsx b/app/(pages)/(hackers)/_components/AuthForms/LoginForm.tsx index c3ebe258e..c3b676e31 100644 --- a/app/(pages)/(hackers)/_components/AuthForms/LoginForm.tsx +++ b/app/(pages)/(hackers)/_components/AuthForms/LoginForm.tsx @@ -40,20 +40,20 @@ export default function LoginForm() { return (
- - -
+ ); } diff --git a/app/(pages)/(hackers)/_components/MentorAndDirectorHelp/MDHelp.tsx b/app/(pages)/(hackers)/_components/MentorAndDirectorHelp/MDHelp.tsx index 7cee21b71..abdd591f6 100644 --- a/app/(pages)/(hackers)/_components/MentorAndDirectorHelp/MDHelp.tsx +++ b/app/(pages)/(hackers)/_components/MentorAndDirectorHelp/MDHelp.tsx @@ -5,28 +5,28 @@ const items = [ { title: 'Mentor Help', description: - 'Get our announcements updates in our discord and instagram blah blah blah blah blah.', + 'Stuck on a problem and need guidance? Contact a HackDavis mentor through our discord.', image: '/components/MDHelp/cow.svg', - link: '#', + link: 'https://discord.gg/wc6QQEc', linkName: 'CONTACT A MENTOR', }, { title: 'Director Help', description: - 'Get our announcements updates in our discord and instagram blah blah blah blah blah.', + 'Got questions about this event? Contact a HackDavis director through our discord.', image: '/components/MDHelp/duck.svg', - link: '#', + link: 'https://discord.gg/wc6QQEc', linkName: 'CONTACT A DIRECTOR', }, ]; export default function cardTest() { return ( -
+
{/* Main Content */} -
+
{/* Items Grid */} -
+
{items.map((item, index) => ( = ({ linkName, }) => { return ( -
+
{/* Image */} -
+
{image} = ({ {linkName} diff --git a/app/(pages)/(hackers)/_components/StayUpToDate/Discord.tsx b/app/(pages)/(hackers)/_components/StayUpToDate/Discord.tsx index df2110abb..c96141e1b 100644 --- a/app/(pages)/(hackers)/_components/StayUpToDate/Discord.tsx +++ b/app/(pages)/(hackers)/_components/StayUpToDate/Discord.tsx @@ -5,11 +5,11 @@ import TextCard from '../BeginnersSection/TextCard'; export default function Discord() { return (
-
+
Date: Thu, 19 Feb 2026 22:21:04 -0800 Subject: [PATCH 7/7] undo auth --- auth.ts | 98 +++++++++++++-------------------------------------------- 1 file changed, 22 insertions(+), 76 deletions(-) diff --git a/auth.ts b/auth.ts index b65b3132d..a82034fe1 100644 --- a/auth.ts +++ b/auth.ts @@ -1,13 +1,12 @@ -import NextAuth, { DefaultSession } from "next-auth"; -import GoogleProvider from "next-auth/providers/google"; -import "next-auth/jwt"; -import Credentials from "next-auth/providers/credentials"; -import { compare } from "bcryptjs"; -import { z } from "zod"; +import NextAuth, { DefaultSession } from 'next-auth'; +import 'next-auth/jwt'; +import Credentials from 'next-auth/providers/credentials'; +import { compare } from 'bcryptjs'; +import { z } from 'zod'; -import { GetManyUsers } from "@datalib/users/getUser"; +import { GetManyUsers } from '@datalib/users/getUser'; -declare module "next-auth" { +declare module 'next-auth' { interface User { id?: string; email?: string | null; @@ -19,11 +18,11 @@ declare module "next-auth" { id: string; email: string; role: string; - } & DefaultSession["user"]; + } & DefaultSession['user']; } } -declare module "next-auth/jwt" { +declare module 'next-auth/jwt' { interface JWT { id: string; email: string; @@ -31,20 +30,20 @@ declare module "next-auth/jwt" { } } -const emailSchema = z.string().email("Invalid email address."); +const emailSchema = z.string().email('Invalid email address.'); const passwordSchema = z .string() - .min(6, { message: "Password must be at least 6 characters long." }) - .max(20, { message: "Password cannot be longer than 20 characters." }); + .min(6, { message: 'Password must be at least 6 characters long.' }) + .max(20, { message: 'Password cannot be longer than 20 characters.' }); export const { auth, handlers, signIn, signOut } = NextAuth({ - session: { strategy: "jwt" }, + session: { strategy: 'jwt' }, providers: [ Credentials({ credentials: { - email: { label: "email", type: "text" }, - password: { label: "password", type: "password" }, + email: { label: 'email', type: 'text' }, + password: { label: 'password', type: 'password' }, }, async authorize(credentials) { try { @@ -56,14 +55,14 @@ export const { auth, handlers, signIn, signOut } = NextAuth({ const response = await GetManyUsers({ email }); if (!response.ok || response.body.length === 0) { - throw new Error(response.error ?? "User not found."); + throw new Error(response.error ?? 'User not found.'); } const user = response.body[0]; const passwordCorrect = await compare(password, user.password); if (!passwordCorrect) { - throw new Error("Invalid email address or password."); + throw new Error('Invalid email address or password.'); } return { @@ -73,82 +72,29 @@ export const { auth, handlers, signIn, signOut } = NextAuth({ }; } catch (error) { if (error instanceof z.ZodError) { - const errorMessage = error.errors.map((e) => e.message).join(" "); + const errorMessage = error.errors.map((e) => e.message).join(' '); throw new Error(errorMessage); } throw error; } }, }), - GoogleProvider({ - clientId: process.env.GOOGLE_CLIENT_ID, - clientSecret: process.env.GOOGLE_CLIENT_SECRET, - authorization: { - params: { - prompt: "consent", - access_type: "offline", - response_type: "code", - scope: "openid email profile", - }, - }, - }), ], callbacks: { async jwt({ token, user }) { - // When user first logs in (Google or Credentials) if (user) { - console.log("Jwt() got user:", user); - // Try to get user data from your MongoDB - const dbUser = await GetManyUsers({ email: user.email }); - if (dbUser.ok && dbUser.body.length > 0) { - token.role = dbUser.body[0].role; - token.id = dbUser.body[0]._id.toString(); - } else { - token.role = "unknown"; - } + token.id = user.id ?? 'User ID not found'; + token.email = user.email ?? 'User email not found'; + token.role = user.role; } - - console.log("Final JWT token:", token); return token; }, async session({ session, token }) { - console.log("Session() token:", token); session.user.id = token.id; session.user.email = token.email; session.user.role = token.role; - console.log("Final session object:", session); return session; }, - async signIn({ account, profile }) { - console.log("Account info:", account); - console.log("Profile info:", profile); - - if (!account || !profile?.email) { - console.log("[NextAuth] Missing account or profile", { - account, - profile, - }); - return false; - } - - if (account?.provider === "google" && profile?.email) { - console.log("Checking MongoDB for:", profile.email); - const response = await GetManyUsers({ email: profile.email }); - console.log("MongoDB lookup result:", response); - - if (!response.ok || response.body.length === 0) { - console.log( - `[NextAuth] Google login denied, user not found: ${profile.email}` - ); - return false; - } - - console.log(`[NextAuth] Google login allowed for: ${profile.email}`); - return true; - } - - return true; - }, }, secret: process.env.AUTH_SECRET, -}); +}); \ No newline at end of file