mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 06:11:11 -05:00
Fix: Ensure authorization header is sent
This commit is contained in:
@@ -148,19 +148,36 @@ export function AccountProfileTab() {
|
||||
|
||||
setCancellingEmail(true);
|
||||
try {
|
||||
// Call the edge function to cancel the email change with admin privileges
|
||||
// Ensure we have a valid session with access token
|
||||
const { data: { session }, error: sessionError } = await supabase.auth.getSession();
|
||||
|
||||
if (sessionError || !session?.access_token) {
|
||||
console.error('Session error:', sessionError);
|
||||
throw new Error('Your session has expired. Please refresh the page and try again.');
|
||||
}
|
||||
|
||||
// Call the edge function with explicit authorization header
|
||||
const { data, error } = await supabase.functions.invoke('cancel-email-change', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${session.access_token}`,
|
||||
},
|
||||
});
|
||||
|
||||
if (error) throw error;
|
||||
if (error) {
|
||||
console.error('Edge function error:', error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (!data?.success) {
|
||||
throw new Error(data?.error || 'Failed to cancel email change');
|
||||
}
|
||||
|
||||
// Force refresh the session to get updated user state
|
||||
await supabase.auth.refreshSession();
|
||||
const { error: refreshError } = await supabase.auth.refreshSession();
|
||||
if (refreshError) {
|
||||
console.error('Session refresh error:', refreshError);
|
||||
}
|
||||
|
||||
// Update Novu subscriber back to current email
|
||||
if (notificationService.isEnabled()) {
|
||||
|
||||
Reference in New Issue
Block a user