@@ -28,6 +28,10 @@ function getGoogleCredentials(): { clientId: string; clientSecret: string } {
2828}
2929
3030export const authOptions : NextAuthOptions = {
31+ debug : true , // Enable NextAuth debugging
32+ //trustHost: true, // Trust the host header (useful for proxies) - CAUSES TYPE ERROR usually, check types first.
33+ // Actually NextAuthOptions type might not have trustHost in v4 types visibly? It does.
34+ // safer to just use debug first.
3135 secret : process . env . JWT_SECRET ,
3236 //adapter: PrismaAdapter(prismadb),
3337 session : {
@@ -114,8 +118,10 @@ export const authOptions: NextAuthOptions = {
114118 } ,
115119
116120 async authorize ( credentials ) {
117- // console.log(credentials, "credentials");
121+ console . log ( "[Auth Debug] Authorize called" ) ;
122+
118123 if ( ! credentials ?. email || ! credentials ?. password ) {
124+ console . log ( "[Auth Debug] Missing credentials" ) ;
119125 throw new Error ( "Email or password is missing" ) ;
120126 }
121127
@@ -125,6 +131,8 @@ export const authOptions: NextAuthOptions = {
125131 ? credentials . email . trim ( ) . toLowerCase ( )
126132 : credentials . email ;
127133
134+ console . log ( `[Auth Debug] Looking up user: ${ normalizedEmail } ` ) ;
135+
128136 const user = await prismadb . users . findFirst ( {
129137 where : {
130138 email : normalizedEmail ,
@@ -135,15 +143,20 @@ export const authOptions: NextAuthOptions = {
135143 const trimmedPassword = credentials . password . trim ( ) ;
136144
137145 if ( ! user ) {
146+ console . log ( "[Auth Debug] User not found in database" ) ;
138147 throw new Error ( "User not found. Please register first." ) ;
139148 }
140149
150+ console . log ( `[Auth Debug] User found: ${ user . id } , Status: ${ user . userStatus } ` ) ;
151+
141152 // Check if user is active
142153 if ( user . userStatus !== "ACTIVE" ) {
154+ console . log ( `[Auth Debug] User inactive. Status: ${ user . userStatus } ` ) ;
143155 throw new Error ( "Your account is pending approval. Please contact support." ) ;
144156 }
145157
146158 if ( ! user ?. password ) {
159+ console . log ( "[Auth Debug] User has no password set (OAuth user?)" ) ;
147160 throw new Error (
148161 "Account exists but no password is set. Sign in with Google/GitHub or use 'Forgot password' to set one."
149162 ) ;
@@ -155,9 +168,11 @@ export const authOptions: NextAuthOptions = {
155168 ) ;
156169
157170 if ( ! isCorrectPassword ) {
171+ console . log ( "[Auth Debug] Password mismatch" ) ;
158172 throw new Error ( "Password is incorrect" ) ;
159173 }
160174
175+ console . log ( "[Auth Debug] Login successful, returning user" ) ;
161176 //console.log(user, "user");
162177 return user ;
163178 } ,
0 commit comments