From 66d33ae9b2b4be97019996c0b76aa79c4f7d0c4b Mon Sep 17 00:00:00 2001 From: zramsay Date: Tue, 11 Mar 2025 16:47:38 -0400 Subject: [PATCH] claude thinks this is interesting --- src/app/api/auth/[...nextauth]/route.ts | 49 ++----------------------- src/app/api/debug/auth-test/route.ts | 30 +++++++++++++++ src/app/debug/page.tsx | 37 ++++++++++++++++++- 3 files changed, 69 insertions(+), 47 deletions(-) create mode 100644 src/app/api/debug/auth-test/route.ts diff --git a/src/app/api/auth/[...nextauth]/route.ts b/src/app/api/auth/[...nextauth]/route.ts index 31520d1..a06f224 100644 --- a/src/app/api/auth/[...nextauth]/route.ts +++ b/src/app/api/auth/[...nextauth]/route.ts @@ -33,7 +33,7 @@ if (!process.env.NEXTAUTH_URL && process.env.NODE_ENV === 'production') { console.log("Warning: NEXTAUTH_URL not explicitly set in production, Next.js will use the Host header"); } -// Define auth options +// Define auth options - using a minimal configuration to isolate the issue const authOptions = { providers: [ GoogleProvider({ @@ -41,52 +41,9 @@ const authOptions = { clientSecret: googleClientSecret, }), ], - pages: { - signIn: '/auth/signin', - signOut: '/auth/signout', - error: '/auth/error', - }, - callbacks: { - async session({ session, token }) { - // Add user info to the session - if (session.user && token.sub) { - session.user.id = token.sub; - } - return session; - }, - // Provide detailed logs for debugging - async signIn({ user, account, profile }) { - console.log(`User attempting to sign in: ${user.email}`); - return true; - } - }, + // Only essential configuration secret: nextAuthSecret, - // Ensure cookies work in production - cookies: { - sessionToken: { - name: process.env.NODE_ENV === 'production' - ? '__Secure-next-auth.session-token' - : 'next-auth.session-token', - options: { - httpOnly: true, - sameSite: "lax" as const, - path: '/', - secure: process.env.NODE_ENV === 'production' - } - } - }, - debug: true, // Enable debug mode to diagnose the issue - logger: { - error(code, ...message) { - console.error(`NextAuth Error [${code}]:`, ...message); - }, - warn(code, ...message) { - console.warn(`NextAuth Warning [${code}]:`, ...message); - }, - debug(code, ...message) { - console.log(`NextAuth Debug [${code}]:`, ...message); - } - } + debug: true, }; // Create detailed error response with full information diff --git a/src/app/api/debug/auth-test/route.ts b/src/app/api/debug/auth-test/route.ts new file mode 100644 index 0000000..14a2c7b --- /dev/null +++ b/src/app/api/debug/auth-test/route.ts @@ -0,0 +1,30 @@ +import { NextRequest, NextResponse } from 'next/server'; + +// This is a simple, direct test of getServerSession +export async function GET(request: NextRequest) { + try { + console.log("Auth test endpoint called"); + + // Create a simplified response with essential info only + return NextResponse.json({ + message: "Auth test endpoint working", + timestamp: new Date().toISOString(), + headers: { + host: request.headers.get('host'), + }, + env: { + node_env: process.env.NODE_ENV, + nextauth_url: process.env.NEXTAUTH_URL, + } + }); + } catch (error) { + console.error('Auth test error:', error); + + // Return the error details + return NextResponse.json({ + error: true, + message: String(error), + stack: error instanceof Error ? error.stack : undefined + }, { status: 500 }); + } +}; \ No newline at end of file diff --git a/src/app/debug/page.tsx b/src/app/debug/page.tsx index a34a3a8..40498c0 100644 --- a/src/app/debug/page.tsx +++ b/src/app/debug/page.tsx @@ -11,6 +11,7 @@ export default function DebugPage() { const [serverEnv, setServerEnv] = useState(null); const [authCheck, setAuthCheck] = useState(null); const [jwtTest, setJwtTest] = useState(null); + const [authTest, setAuthTest] = useState(null); const [authError, setAuthError] = useState(null); useEffect(() => { @@ -103,11 +104,31 @@ export default function DebugPage() { console.error('Error testing JWT functionality:', error); } }; + + const testAuthEndpoint = async () => { + try { + const res = await fetch('/api/debug/auth-test'); + const text = await res.text(); + console.log('Auth test endpoint raw response:', text); + + try { + const data = JSON.parse(text); + setAuthTest(data); + } catch (e) { + console.error('Could not parse auth test response:', e); + setAuthTest({ error: true, raw: text.substring(0, 500) }); + } + } catch (error) { + console.error('Error testing auth endpoint:', error); + setAuthTest({ error: true, message: String(error) }); + } + }; checkAuth(); checkServerEnv(); checkAuthConfig(); testJwtFunctionality(); + testAuthEndpoint(); }, []); // Environment variables check (public variables only) @@ -168,6 +189,13 @@ export default function DebugPage() { +
+

Simple Auth Test Endpoint

+
+              {authTest ? JSON.stringify(authTest, null, 2) : "Testing auth endpoint..."}
+            
+
+

Client Environment Variables

@@ -189,9 +217,16 @@ export default function DebugPage() {
                 onClick={() => signIn('google', { callbackUrl: '/' })}
                 className="px-4 py-2 bg-blue-600 hover:bg-blue-700 rounded"
               >
-                Sign in with Google
+                Sign in with Google (Client)
               
               
+              
+                Sign in with Google (Direct)
+              
+