mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 15:11:13 -05:00
Fix edge function to clear new_email
This commit is contained in:
@@ -37,13 +37,18 @@ Deno.serve(async (req) => {
|
|||||||
throw new Error('Unauthorized');
|
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(
|
const { data: updatedUser, error: updateError } = await supabaseAdmin.auth.admin.updateUserById(
|
||||||
user.id,
|
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;
|
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
|
// Log the cancellation in admin_audit_log
|
||||||
const { error: auditError } = await supabaseAdmin
|
const { error: auditError } = await supabaseAdmin
|
||||||
|
|||||||
Reference in New Issue
Block a user