Fix edge function to clear new_email

This commit is contained in:
gpt-engineer-app[bot]
2025-10-01 15:59:52 +00:00
parent 13626922cc
commit de284a4328

View File

@@ -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