Fix send-auth-otp: Remove notification_logs references
- Remove notification_logs table references (table doesn't exist) - This was causing the function to crash after sending email - Now the function should complete successfully - Added better email payload logging - Keep .env file for local development
This commit is contained in:
@@ -138,7 +138,6 @@ serve(async (req: Request) => {
|
||||
hasFromName: !!settings.from_name,
|
||||
hasFromEmail: !!settings.from_email,
|
||||
platformName: settings.platform_name,
|
||||
allSettings: JSON.stringify(settings)
|
||||
});
|
||||
|
||||
// Use api_token (not mailketing_api_token)
|
||||
@@ -148,6 +147,16 @@ serve(async (req: Request) => {
|
||||
throw new Error('API token not found in notification_settings');
|
||||
}
|
||||
|
||||
// Log email details (truncate HTML body for readability)
|
||||
console.log('Email payload:', {
|
||||
to: email,
|
||||
from_name: settings.from_name || settings.platform_name || 'Admin',
|
||||
from_email: settings.from_email || 'noreply@example.com',
|
||||
subject: subject,
|
||||
html_body_length: htmlBody.length,
|
||||
html_body_preview: htmlBody.substring(0, 200),
|
||||
});
|
||||
|
||||
const emailResponse = await fetch(`${supabaseUrl}/functions/v1/send-email-v2`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -173,17 +182,7 @@ serve(async (req: Request) => {
|
||||
const emailResult = await emailResponse.json();
|
||||
console.log('Email sent successfully:', emailResult);
|
||||
|
||||
// Log notification
|
||||
await supabase
|
||||
.from('notification_logs')
|
||||
.insert({
|
||||
user_id,
|
||||
email: email,
|
||||
notification_type: 'auth_email_verification',
|
||||
status: 'sent',
|
||||
provider: 'mailketing',
|
||||
error_message: null,
|
||||
});
|
||||
// Note: notification_logs table doesn't exist, skipping logging
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
@@ -196,25 +195,7 @@ serve(async (req: Request) => {
|
||||
} catch (error: any) {
|
||||
console.error("Error sending OTP:", error);
|
||||
|
||||
// Try to log error notification
|
||||
try {
|
||||
const supabaseUrl = Deno.env.get('SUPABASE_URL')!;
|
||||
const supabaseServiceKey = Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!;
|
||||
const supabase = createClient(supabaseUrl, supabaseServiceKey);
|
||||
|
||||
await supabase
|
||||
.from('notification_logs')
|
||||
.insert({
|
||||
user_id: null,
|
||||
email: null,
|
||||
notification_type: 'auth_email_verification',
|
||||
status: 'failed',
|
||||
provider: 'mailketing',
|
||||
error_message: error.message || 'Unknown error',
|
||||
});
|
||||
} catch (logError) {
|
||||
console.error('Failed to log error:', logError);
|
||||
}
|
||||
// Note: notification_logs table doesn't exist, skipping error logging
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
|
||||
Reference in New Issue
Block a user