courrier msft oauth
This commit is contained in:
parent
758607d05f
commit
06de428e61
@ -34,10 +34,10 @@ interface EmailCredentialsExtended extends EmailCredentials {
|
|||||||
|
|
||||||
// Define the extended MailCredentials type that includes OAuth fields
|
// Define the extended MailCredentials type that includes OAuth fields
|
||||||
interface MailCredentialsWithOAuth extends MailCredentials {
|
interface MailCredentialsWithOAuth extends MailCredentials {
|
||||||
use_oauth?: boolean;
|
useOAuth?: boolean;
|
||||||
access_token?: string | null;
|
accessToken?: string | null;
|
||||||
refresh_token?: string | null;
|
refreshToken?: string | null;
|
||||||
token_expiry?: Date | null;
|
tokenExpiry?: Date | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Types specific to this service
|
// Types specific to this service
|
||||||
@ -277,9 +277,10 @@ export async function getImapConnection(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Map database fields to our credential format
|
// Map database fields to our credential format
|
||||||
|
if (dbCredentials) {
|
||||||
credentials = {
|
credentials = {
|
||||||
email: dbCredentials.email,
|
email: dbCredentials.email,
|
||||||
password: dbCredentials.password,
|
password: dbCredentials.password || '',
|
||||||
host: dbCredentials.host,
|
host: dbCredentials.host,
|
||||||
port: dbCredentials.port,
|
port: dbCredentials.port,
|
||||||
secure: dbCredentials.secure,
|
secure: dbCredentials.secure,
|
||||||
@ -289,12 +290,12 @@ export async function getImapConnection(
|
|||||||
display_name: dbCredentials.display_name || undefined,
|
display_name: dbCredentials.display_name || undefined,
|
||||||
color: dbCredentials.color || undefined,
|
color: dbCredentials.color || undefined,
|
||||||
|
|
||||||
// Map OAuth fields
|
// Map OAuth fields - using camelCase field names from the schema
|
||||||
useOAuth: dbCredentials.use_oauth || false,
|
useOAuth: dbCredentials.useOAuth || false,
|
||||||
accessToken: dbCredentials.access_token || undefined,
|
accessToken: dbCredentials.accessToken || undefined,
|
||||||
refreshToken: dbCredentials.refresh_token || undefined,
|
refreshToken: dbCredentials.refreshToken || undefined,
|
||||||
tokenExpiry: dbCredentials.token_expiry ? dbCredentials.token_expiry.getTime() : undefined
|
tokenExpiry: dbCredentials.tokenExpiry ? dbCredentials.tokenExpiry.getTime() : undefined
|
||||||
};
|
} as EmailCredentialsExtended; // Cast to extended type
|
||||||
|
|
||||||
// Log credentials (safely)
|
// Log credentials (safely)
|
||||||
console.log('Loaded credentials from database:', {
|
console.log('Loaded credentials from database:', {
|
||||||
@ -310,6 +311,7 @@ export async function getImapConnection(
|
|||||||
// Cache the credentials for future use
|
// Cache the credentials for future use
|
||||||
await cacheEmailCredentials(userId, accountId, credentials);
|
await cacheEmailCredentials(userId, accountId, credentials);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Cast to extended type
|
// Cast to extended type
|
||||||
const extendedCreds = credentials as EmailCredentialsExtended;
|
const extendedCreds = credentials as EmailCredentialsExtended;
|
||||||
@ -559,20 +561,20 @@ export async function saveUserEmailCredentials(
|
|||||||
smtp_secure: credentials.smtp_secure ?? false,
|
smtp_secure: credentials.smtp_secure ?? false,
|
||||||
display_name: credentials.display_name || null,
|
display_name: credentials.display_name || null,
|
||||||
color: credentials.color || null,
|
color: credentials.color || null,
|
||||||
// Add OAuth fields if present
|
// Add OAuth fields if present - using the camelCase names from the schema
|
||||||
use_oauth: extendedCreds.useOAuth ?? false,
|
useOAuth: extendedCreds.useOAuth ?? false,
|
||||||
access_token: extendedCreds.accessToken || null,
|
accessToken: extendedCreds.accessToken || null,
|
||||||
refresh_token: extendedCreds.refreshToken || null,
|
refreshToken: extendedCreds.refreshToken || null,
|
||||||
token_expiry: extendedCreds.tokenExpiry ? new Date(extendedCreds.tokenExpiry) : null
|
tokenExpiry: extendedCreds.tokenExpiry ? new Date(extendedCreds.tokenExpiry) : null
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log('Saving credentials with OAuth data:', {
|
console.log('Saving credentials with OAuth data:', {
|
||||||
...dbCredentials,
|
...dbCredentials,
|
||||||
password: dbCredentials.password ? '***' : null,
|
password: dbCredentials.password ? '***' : null,
|
||||||
access_token: dbCredentials.access_token ? '***' : null,
|
accessToken: dbCredentials.accessToken ? '***' : null,
|
||||||
refresh_token: dbCredentials.refresh_token ? '***' : null,
|
refreshToken: dbCredentials.refreshToken ? '***' : null,
|
||||||
use_oauth: dbCredentials.use_oauth
|
useOAuth: dbCredentials.useOAuth
|
||||||
});
|
});
|
||||||
|
|
||||||
// Save to database using the unique constraint on [userId, email]
|
// Save to database using the unique constraint on [userId, email]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user