feat: refactor account deletion to handle requires-recent-login and update Android package ID.

This commit is contained in:
Van Leemput Dayron
2025-11-28 19:01:01 +01:00
parent b1f86b1c6a
commit 0668fcad57
7 changed files with 336 additions and 124 deletions

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:travel_mate/components/widgets/user_state_widget.dart';
import 'package:travel_mate/services/error_service.dart';
@@ -789,7 +790,7 @@ class ProfileContent extends StatelessWidget {
BuildContext context,
user_state.UserModel user,
) {
final passwordController = TextEditingController();
final confirmationController = TextEditingController();
final authService = AuthService();
showDialog(
@@ -801,15 +802,15 @@ class ProfileContent extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Êtes-vous sûr de vouloir supprimer votre compte ? Cette action est irréversible.',
'Êtes-vous sûr de vouloir supprimer votre compte ? Cette action est irréversible.\n\nPour confirmer, veuillez écrire "CONFIRMER" ci-dessous.',
),
SizedBox(height: 16),
TextField(
controller: passwordController,
obscureText: true,
controller: confirmationController,
decoration: InputDecoration(
labelText: 'Confirmez votre mot de passe',
labelText: 'Écrivez CONFIRMER',
border: OutlineInputBorder(),
hintText: 'CONFIRMER',
),
),
],
@@ -821,11 +822,18 @@ class ProfileContent extends StatelessWidget {
),
TextButton(
onPressed: () async {
try {
await authService.deleteAccount(
password: passwordController.text,
email: user.email,
if (confirmationController.text != 'CONFIRMER') {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Veuillez écrire CONFIRMER pour valider'),
backgroundColor: Colors.red,
),
);
return;
}
try {
await authService.deleteAccount();
if (context.mounted) {
Navigator.of(dialogContext).pop();
@@ -836,10 +844,33 @@ class ProfileContent extends StatelessWidget {
(route) => false,
);
}
} on FirebaseAuthException catch (e) {
if (e.code == 'requires-recent-login') {
if (context.mounted) {
Navigator.of(dialogContext).pop();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'Par sécurité, veuillez vous reconnecter avant de supprimer votre compte',
),
backgroundColor: Colors.orange,
duration: Duration(seconds: 4),
),
);
}
} else {
if (context.mounted) {
_errorService.showError(
message: 'Erreur lors de la suppression: ${e.message}',
);
}
}
} catch (e) {
_errorService.showError(
message: 'Erreur: Mot de passe incorrect',
);
if (context.mounted) {
_errorService.showError(
message: 'Erreur inattendue: ${e.toString()}',
);
}
}
},
style: TextButton.styleFrom(foregroundColor: Colors.red),