Fix email system error handling and remove hardcoded credentials

- Handle missing email sessions gracefully without throwing errors
- Clear partial session data when no valid session exists
- Return empty results instead of 401 errors for missing credentials
- Remove hardcoded Documenso API key and require env variables
- Reduce email fetch limit from 50 to 20 for performance
- Add documentation for email system fixes
This commit is contained in:
2025-06-09 22:50:06 +02:00
parent f7cc2973e1
commit 5f10e9fb54
5 changed files with 103 additions and 9 deletions

View File

@@ -36,10 +36,12 @@ export default defineEventHandler(async (event) => {
// Get encrypted credentials from session
const encryptedCredentials = getCredentialsFromSession(sessionId);
if (!encryptedCredentials) {
throw createError({
statusCode: 401,
statusMessage: "Email credentials not found. Please reconnect."
});
// Return empty results instead of throwing error
return {
success: true,
emails: [],
threads: []
};
}
// Decrypt credentials

View File

@@ -80,10 +80,17 @@ export default defineEventHandler(async (event) => {
const berthNumbers = berths.map(b => b['Mooring Number']).join(', ');
// Documenso API configuration
const documensoApiKey = process.env.NUXT_DOCUMENSO_API_KEY || 'api_malptg62zqyb0wrp';
const documensoBaseUrl = process.env.NUXT_DOCUMENSO_BASE_URL || 'https://signatures.portnimara.dev';
const documensoApiKey = process.env.NUXT_DOCUMENSO_API_KEY;
const documensoBaseUrl = process.env.NUXT_DOCUMENSO_BASE_URL;
const templateId = '9';
if (!documensoApiKey || !documensoBaseUrl) {
throw createError({
statusCode: 500,
statusMessage: "Documenso configuration missing. Please check NUXT_DOCUMENSO_API_KEY and NUXT_DOCUMENSO_BASE_URL environment variables."
});
}
// 1. Get template (optional - just to verify it exists)
try {
const templateResponse = await fetch(`${documensoBaseUrl}/api/v1/templates/${templateId}`, {