fix: prevent session loading hang from JWT callback DB failure
JWT callback was querying DB on every request which could hang if DB is slow. Now only queries when token.id is missing, and wraps in try/catch so session still resolves on DB errors. v1.52.1 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
234bb25c1e
commit
3c17f6a89d
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "my-weekly-todo-list",
|
||||
"version": "1.52.0",
|
||||
"version": "1.52.1",
|
||||
"description": "A web-based weekly task management application that organizes to-dos and calendar events in a single, intuitive weekly view",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
||||
@ -113,14 +113,18 @@ export const authOptions: NextAuthOptions = {
|
||||
if (user) {
|
||||
token.id = user.id;
|
||||
}
|
||||
// Refresh user ID from DB to handle stale sessions after DB changes
|
||||
if (token.email) {
|
||||
const dbUser = await prisma.user.findUnique({
|
||||
where: { email: token.email as string },
|
||||
select: { id: true }
|
||||
});
|
||||
if (dbUser) {
|
||||
token.id = dbUser.id;
|
||||
// Refresh user ID from DB periodically (not on every request)
|
||||
if (token.email && !token.id) {
|
||||
try {
|
||||
const dbUser = await prisma.user.findUnique({
|
||||
where: { email: token.email as string },
|
||||
select: { id: true }
|
||||
});
|
||||
if (dbUser) {
|
||||
token.id = dbUser.id;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("[AUTH] JWT callback DB lookup failed:", e);
|
||||
}
|
||||
}
|
||||
return token;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user