From a56e8e4cf6ab177c0ef3234317c534dbadf45a7d Mon Sep 17 00:00:00 2001 From: alma Date: Mon, 5 May 2025 19:19:52 +0200 Subject: [PATCH] build fix --- lib/imap.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/imap.ts b/lib/imap.ts index a8e21d7d..b507fadf 100644 --- a/lib/imap.ts +++ b/lib/imap.ts @@ -3,6 +3,7 @@ import { getServerSession } from 'next-auth'; import { authOptions } from "@/app/api/auth/options"; import { prisma } from '@/lib/prisma'; import { getCachedEmailCredentials } from '@/lib/redis'; +import { EmailCredentials } from '@/lib/types'; export async function getImapClient() { const session = await getServerSession(authOptions); @@ -16,11 +17,32 @@ export async function getImapClient() { // If not in cache, get from database if (!credentials) { console.log(`Credentials not found in cache for ${session.user.id}, checking database`); - credentials = await prisma.mailCredentials.findUnique({ + const dbCredentials = await prisma.mailCredentials.findFirst({ where: { userId: session.user.id } }); + + // Convert database model to EmailCredentials + if (dbCredentials) { + const dbCreds = dbCredentials as any; + + credentials = { + email: dbCreds.email, + password: dbCreds.password || undefined, // Convert null to undefined + host: dbCreds.host, + port: dbCreds.port, + secure: dbCreds.secure, + useOAuth: dbCreds.use_oauth, + accessToken: dbCreds.access_token || undefined, + refreshToken: dbCreds.refresh_token || undefined, + smtp_host: dbCreds.smtp_host || undefined, + smtp_port: dbCreds.smtp_port || undefined, // Handle null + smtp_secure: dbCreds.smtp_secure || undefined, // Handle null + display_name: dbCreds.display_name || undefined, + color: dbCreds.color || undefined, + }; + } } if (!credentials) {