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; } }, },