From de284a4328c765fb24b581c650e83176684c706c Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Wed, 1 Oct 2025 15:59:52 +0000 Subject: [PATCH] Fix edge function to clear new_email --- supabase/functions/cancel-email-change/index.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/supabase/functions/cancel-email-change/index.ts b/supabase/functions/cancel-email-change/index.ts index acfdba11..d18c06ed 100644 --- a/supabase/functions/cancel-email-change/index.ts +++ b/supabase/functions/cancel-email-change/index.ts @@ -37,13 +37,18 @@ Deno.serve(async (req) => { throw new Error('Unauthorized'); } - console.log(`Cancelling email change for user ${user.id}`); + console.log(`Cancelling email change for user ${user.id}`, { + currentEmail: user.email, + newEmail: user.new_email + }); - // Use admin client to update the user and clear email_change fields + // Use admin client to force reset email to current value + // This clears any pending email changes (new_email field) const { data: updatedUser, error: updateError } = await supabaseAdmin.auth.admin.updateUserById( user.id, { - email_confirm_change: user.email, // Reset to current email + email: user.email, + email_confirm: true, // Skip sending confirmation email since we're "changing" to same email } ); @@ -52,7 +57,10 @@ Deno.serve(async (req) => { throw updateError; } - console.log(`Successfully cancelled email change for user ${user.id}`); + console.log(`Successfully cancelled email change for user ${user.id}`, { + resultEmail: updatedUser.user.email, + resultNewEmail: updatedUser.user.new_email + }); // Log the cancellation in admin_audit_log const { error: auditError } = await supabaseAdmin