Fix edge function and force session refresh

This commit is contained in:
gpt-engineer-app[bot]
2025-10-01 16:14:59 +00:00
parent 50273ed620
commit 11e6b2bf46
2 changed files with 7 additions and 14 deletions

View File

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

View File

@@ -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,
},
}),
{