From 6c74bb8bcf014769ae6ab63a161c568deb254c78 Mon Sep 17 00:00:00 2001 From: Arthur Belleville Date: Wed, 29 Apr 2026 15:51:38 +0200 Subject: [PATCH] fix(expo): harden account deletion handler - Add isDeletingAccount ref to prevent double-tap race - Guard against null session before calling API - Set 15s timeout on delete request (API makes 3-4 Supabase round-trips) - Log error to console and restore guard in finally block Co-Authored-By: Claude Sonnet 4.6 (1M context) --- xtablo-expo/app/(app)/(tabs)/settings.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/xtablo-expo/app/(app)/(tabs)/settings.tsx b/xtablo-expo/app/(app)/(tabs)/settings.tsx index 3e25467..9e99eb5 100644 --- a/xtablo-expo/app/(app)/(tabs)/settings.tsx +++ b/xtablo-expo/app/(app)/(tabs)/settings.tsx @@ -61,6 +61,7 @@ export default function SettingsScreen() { const [pushNotifications, setPushNotifications] = useState(true); const [emailNotifications, setEmailNotifications] = useState(true); const [biometricAuth, setBiometricAuth] = useState(false); + const isDeletingAccount = React.useRef(false); const handleSignOut = () => { Alert.alert("Déconnexion", "Êtes-vous sûr de vouloir vous déconnecter ?", [ @@ -90,17 +91,27 @@ export default function SettingsScreen() { text: "Supprimer mon compte", style: "destructive", onPress: async () => { + if (isDeletingAccount.current) return; + isDeletingAccount.current = true; try { const session = useAuthStore.getState().session; + if (!session) { + Alert.alert("Erreur", "Session expirée. Veuillez vous reconnecter."); + return; + } await api.delete("/api/v1/users/me", { - headers: { Authorization: `Bearer ${session?.access_token}` }, + headers: { Authorization: `Bearer ${session.access_token}` }, + timeout: 15000, }); await signOut(); - } catch { + } catch (error) { + console.error("Account deletion error:", error); Alert.alert( "Erreur", "Une erreur est survenue lors de la suppression de votre compte. Veuillez réessayer." ); + } finally { + isDeletingAccount.current = false; } }, },