build fix
This commit is contained in:
parent
bafea2c986
commit
a56e8e4cf6
24
lib/imap.ts
24
lib/imap.ts
@ -3,6 +3,7 @@ import { getServerSession } from 'next-auth';
|
|||||||
import { authOptions } from "@/app/api/auth/options";
|
import { authOptions } from "@/app/api/auth/options";
|
||||||
import { prisma } from '@/lib/prisma';
|
import { prisma } from '@/lib/prisma';
|
||||||
import { getCachedEmailCredentials } from '@/lib/redis';
|
import { getCachedEmailCredentials } from '@/lib/redis';
|
||||||
|
import { EmailCredentials } from '@/lib/types';
|
||||||
|
|
||||||
export async function getImapClient() {
|
export async function getImapClient() {
|
||||||
const session = await getServerSession(authOptions);
|
const session = await getServerSession(authOptions);
|
||||||
@ -16,11 +17,32 @@ export async function getImapClient() {
|
|||||||
// If not in cache, get from database
|
// If not in cache, get from database
|
||||||
if (!credentials) {
|
if (!credentials) {
|
||||||
console.log(`Credentials not found in cache for ${session.user.id}, checking database`);
|
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: {
|
where: {
|
||||||
userId: session.user.id
|
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) {
|
if (!credentials) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user