From 83c30b5bd15eed1266b14d38cbd767bc14c0e1c2 Mon Sep 17 00:00:00 2001 From: ilia Date: Sun, 4 Jan 2026 13:09:04 -0500 Subject: [PATCH] feat: Add debug logging for authentication process in session route - Introduced console logs to track the authentication call and its results, including session presence and user details. - Enhanced error logging to capture and display authentication errors for improved debugging. --- lib/auth.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/auth.ts b/lib/auth.ts index 03f5b8b..d034f3a 100644 --- a/lib/auth.ts +++ b/lib/auth.ts @@ -75,6 +75,13 @@ export const { handlers, auth, signIn, signOut } = NextAuth({ return token }, async session({ session, token }) { + console.log("Session callback: called", { + hasToken: !!token, + hasSession: !!session, + tokenId: token?.id, + tokenEmail: token?.email, + stackTrace: new Error().stack?.split('\n').slice(1, 4).join('\n') + }) // Always ensure session.user exists when token exists if (token && (token.id || token.email)) { // Ensure session.user is always an object @@ -108,7 +115,10 @@ export const { handlers, auth, signIn, signOut } = NextAuth({ tokenId: token?.id, tokenEmail: token?.email }) + // Return null if no valid token - this will cause auth() to return null + return null } + // Explicitly return session to ensure it's returned return session } },