feat: Enhance session logging in authentication
- Updated session callback to include user role in the logging output for better context during session creation. - Improved logging for missing or invalid tokens by adding token ID and email to the warning message. - Removed conditional logging for non-production environments to ensure consistent logging across all environments.
This commit is contained in:
parent
9457f08580
commit
fcd1d372b7
19
lib/auth.ts
19
lib/auth.ts
@ -84,21 +84,22 @@ export const { handlers, auth, signIn, signOut } = NextAuth({
|
||||
name: (token.name as string) || session.user?.name || "",
|
||||
role: token.role as string,
|
||||
}
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
console.log("Session callback: session created", {
|
||||
userId: token.id,
|
||||
email: token.email,
|
||||
hasUser: !!session.user,
|
||||
userKeys: session.user ? Object.keys(session.user) : []
|
||||
})
|
||||
}
|
||||
console.log("Session callback: session created", {
|
||||
userId: token.id,
|
||||
email: token.email,
|
||||
hasUser: !!session.user,
|
||||
userKeys: session.user ? Object.keys(session.user) : [],
|
||||
userRole: token.role
|
||||
})
|
||||
} else {
|
||||
console.warn("Session callback: token missing or invalid", {
|
||||
hasToken: !!token,
|
||||
tokenKeys: token ? Object.keys(token) : [],
|
||||
hasSession: !!session,
|
||||
sessionKeys: session ? Object.keys(session) : [],
|
||||
sessionUser: session?.user
|
||||
sessionUser: session?.user,
|
||||
tokenId: token?.id,
|
||||
tokenEmail: token?.email
|
||||
})
|
||||
}
|
||||
return session
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user