claude thinks this is interesting

This commit is contained in:
zramsay 2025-03-11 16:47:38 -04:00
parent a12079649c
commit 66d33ae9b2
3 changed files with 69 additions and 47 deletions

View File

@ -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

View File

@ -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 });
}
};

View File

@ -11,6 +11,7 @@ export default function DebugPage() {
const [serverEnv, setServerEnv] = useState<any>(null);
const [authCheck, setAuthCheck] = useState<any>(null);
const [jwtTest, setJwtTest] = useState<any>(null);
const [authTest, setAuthTest] = useState<any>(null);
const [authError, setAuthError] = useState<string | null>(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() {
</pre>
</div>
<div className="bg-gray-700 p-4 rounded-lg">
<h2 className="text-xl font-bold text-emerald-300 mb-2">Simple Auth Test Endpoint</h2>
<pre className="bg-gray-900 p-4 rounded mt-2 overflow-auto max-h-60">
{authTest ? JSON.stringify(authTest, null, 2) : "Testing auth endpoint..."}
</pre>
</div>
<div className="bg-gray-700 p-4 rounded-lg">
<h2 className="text-xl font-bold text-emerald-300 mb-2">Client Environment Variables</h2>
<pre className="bg-gray-900 p-4 rounded mt-2 overflow-auto max-h-60">
@ -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)
</button>
<a
href="/api/auth/signin/google?callbackUrl=/"
className="px-4 py-2 bg-green-600 hover:bg-green-700 rounded inline-block"
>
Sign in with Google (Direct)
</a>
<button
onClick={() => signOut({ callbackUrl: '/' })}
className="px-4 py-2 bg-red-600 hover:bg-red-700 rounded"