Skip to content

Commit 6cd52e6

Browse files
committed
Try/catch authentication for paiement module.
To handle the exceptions in a better way we should use the exceptions of the package local_auth when this gets released: flutter/packages#10147.
1 parent 7f92e22 commit 6cd52e6

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

lib/paiement/ui/pages/pay_page/confirm_button.dart

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:flutter/foundation.dart';
12
import 'package:flutter/material.dart';
23
import 'package:heroicons/heroicons.dart';
34
import 'package:hooks_riverpod/hooks_riverpod.dart';
@@ -124,16 +125,28 @@ class ConfirmButton extends ConsumerWidget {
124125
);
125126
return;
126127
}
127-
final bool didAuthenticate = await auth.authenticate(
128-
localizedReason: 'Veuillez vous authentifier pour payer',
129-
authMessages: [
130-
const AndroidAuthMessages(
131-
signInTitle: 'L\'authentification est requise pour payer',
132-
cancelButton: 'Non merci',
133-
),
134-
const IOSAuthMessages(cancelButton: 'Non merci'),
135-
],
136-
);
128+
late bool didAuthenticate;
129+
try {
130+
didAuthenticate = await auth.authenticate(
131+
localizedReason: 'Veuillez vous authentifier pour payer',
132+
authMessages: [
133+
const AndroidAuthMessages(
134+
signInTitle: 'L\'authentification est requise pour payer',
135+
cancelButton: 'Non merci',
136+
),
137+
const IOSAuthMessages(cancelButton: 'Non merci'),
138+
],
139+
);
140+
} catch (e) {
141+
if (kDebugMode) {
142+
debugPrint('Authentication failed with error : $e');
143+
}
144+
displayToastWithContext(
145+
TypeMsg.error,
146+
'Erreur lors de l\'authentification',
147+
);
148+
return;
149+
}
137150
if (!didAuthenticate) {
138151
displayToastWithContext(
139152
TypeMsg.error,

0 commit comments

Comments
 (0)