feat: Create edge function to cancel email changes

This commit is contained in:
gpt-engineer-app[bot]
2025-10-01 15:57:30 +00:00
parent 8453940656
commit 13626922cc
3 changed files with 114 additions and 16 deletions

View File

@@ -148,12 +148,16 @@ export function AccountProfileTab() {
setCancellingEmail(true);
try {
// Reset email to current email (effectively cancels the pending change)
const { error: updateError } = await supabase.auth.updateUser({
email: user.email
// Call the edge function to cancel the email change with admin privileges
const { data, error } = await supabase.functions.invoke('cancel-email-change', {
method: 'POST',
});
if (updateError) throw updateError;
if (error) throw error;
if (!data?.success) {
throw new Error(data?.error || 'Failed to cancel email change');
}
// Update Novu subscriber back to current email
if (notificationService.isEnabled()) {
@@ -164,18 +168,6 @@ export function AccountProfileTab() {
});
}
// Log the cancellation in audit log
await supabase.from('admin_audit_log').insert({
admin_user_id: user.id,
target_user_id: user.id,
action: 'email_change_cancelled',
details: {
cancelled_email: pendingEmail,
current_email: user.email,
timestamp: new Date().toISOString()
}
});
sonnerToast.success('Email change cancelled', {
description: 'Your email change request has been cancelled.'
});