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) <noreply@anthropic.com>
This commit is contained in:
parent
ea90d5133c
commit
6c74bb8bcf
1 changed files with 13 additions and 2 deletions
|
|
@ -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;
|
||||
}
|
||||
},
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue