mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 06:31:13 -05:00
feat: Create edge function to cancel email changes
This commit is contained in:
@@ -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.'
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user