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.
This commit is contained in:
parent
b7c789b536
commit
83c30b5bd1
10
lib/auth.ts
10
lib/auth.ts
@ -75,6 +75,13 @@ export const { handlers, auth, signIn, signOut } = NextAuth({
|
|||||||
return token
|
return token
|
||||||
},
|
},
|
||||||
async session({ session, 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
|
// Always ensure session.user exists when token exists
|
||||||
if (token && (token.id || token.email)) {
|
if (token && (token.id || token.email)) {
|
||||||
// Ensure session.user is always an object
|
// Ensure session.user is always an object
|
||||||
@ -108,7 +115,10 @@ export const { handlers, auth, signIn, signOut } = NextAuth({
|
|||||||
tokenId: token?.id,
|
tokenId: token?.id,
|
||||||
tokenEmail: token?.email
|
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
|
return session
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user