Fix email unconfirmed login flow with OTP resend and update email API field names
This commit is contained in:
@@ -84,6 +84,19 @@ serve(async (req: Request) => {
|
||||
throw new Error('Notification settings not configured');
|
||||
}
|
||||
|
||||
// Get platform settings for brand_name
|
||||
const { data: platformSettings, error: platformError } = await supabase
|
||||
.from('platform_settings')
|
||||
.select('brand_name')
|
||||
.single();
|
||||
|
||||
if (platformError) {
|
||||
console.error('Error fetching platform settings:', platformError);
|
||||
// Continue with fallback if platform settings not found
|
||||
}
|
||||
|
||||
const brandName = platformSettings?.brand_name || settings.platform_name || 'ACCESS HUB';
|
||||
|
||||
// Get email template
|
||||
console.log('Fetching email template with key: auth_email_verification');
|
||||
|
||||
@@ -110,7 +123,7 @@ serve(async (req: Request) => {
|
||||
|
||||
// Prepare template variables
|
||||
const templateVars = {
|
||||
platform_name: settings.platform_name || 'Platform',
|
||||
platform_name: brandName,
|
||||
nama: user.user_metadata?.name || user.email || 'Pengguna',
|
||||
email: email,
|
||||
otp_code: otpCode,
|
||||
@@ -135,7 +148,7 @@ serve(async (req: Request) => {
|
||||
const htmlBody = EmailTemplateRenderer.render({
|
||||
subject: subject,
|
||||
content: htmlContent,
|
||||
brandName: settings.platform_name || 'ACCESS HUB',
|
||||
brandName: brandName,
|
||||
});
|
||||
|
||||
// Send email via send-email-v2
|
||||
@@ -157,12 +170,12 @@ serve(async (req: Request) => {
|
||||
|
||||
// Log email details (truncate HTML body for readability)
|
||||
console.log('Email payload:', {
|
||||
to: email,
|
||||
from_name: settings.from_name || settings.platform_name || 'Admin',
|
||||
recipient: email,
|
||||
from_name: settings.from_name || brandName,
|
||||
from_email: settings.from_email || 'noreply@example.com',
|
||||
subject: subject,
|
||||
html_body_length: htmlBody.length,
|
||||
html_body_preview: htmlBody.substring(0, 200),
|
||||
content_length: htmlBody.length,
|
||||
content_preview: htmlBody.substring(0, 200),
|
||||
});
|
||||
|
||||
const emailResponse = await fetch(`${supabaseUrl}/functions/v1/send-email-v2`, {
|
||||
@@ -172,12 +185,12 @@ serve(async (req: Request) => {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
to: email,
|
||||
recipient: email,
|
||||
api_token: apiToken,
|
||||
from_name: settings.from_name || settings.platform_name || 'Admin',
|
||||
from_name: settings.from_name || brandName,
|
||||
from_email: settings.from_email || 'noreply@example.com',
|
||||
subject: subject,
|
||||
html_body: htmlBody,
|
||||
content: htmlBody,
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user