diff --git a/src/components/settings/AccountProfileTab.tsx b/src/components/settings/AccountProfileTab.tsx index 9480e495..206b4f53 100644 --- a/src/components/settings/AccountProfileTab.tsx +++ b/src/components/settings/AccountProfileTab.tsx @@ -159,6 +159,9 @@ export function AccountProfileTab() { throw new Error(data?.error || 'Failed to cancel email change'); } + // Force refresh the session to get updated user state + await supabase.auth.refreshSession(); + // Update Novu subscriber back to current email if (notificationService.isEnabled()) { await notificationService.updateSubscriber({ diff --git a/supabase/functions/cancel-email-change/index.ts b/supabase/functions/cancel-email-change/index.ts index 067258e0..e92aac05 100644 --- a/supabase/functions/cancel-email-change/index.ts +++ b/supabase/functions/cancel-email-change/index.ts @@ -52,17 +52,7 @@ Deno.serve(async (req) => { throw new Error('Unable to cancel email change: ' + (cancelError?.message || 'Unknown error')); } - // Verify the change was successful by getting the updated user - const { data: { user: verifiedUser }, error: verifyError } = await supabaseAdmin.auth.admin.getUserById(user.id); - - if (verifyError) { - console.error('Error verifying email change cancellation:', verifyError); - } - - console.log(`Successfully cancelled email change for user ${user.id}`, { - verifiedEmail: verifiedUser?.email, - verifiedNewEmail: verifiedUser?.new_email - }); + console.log(`Successfully cancelled email change for user ${user.id}`); // Log the cancellation in admin_audit_log const { error: auditError } = await supabaseAdmin @@ -87,9 +77,9 @@ Deno.serve(async (req) => { success: true, message: 'Email change cancelled successfully', user: { - id: verifiedUser?.id ?? user.id, - email: verifiedUser?.email ?? user.email, - new_email: verifiedUser?.new_email ?? null, + id: user.id, + email: user.email, + new_email: null, }, }), {