@@ -292,8 +292,8 @@ class _VerifyPhoneNumberScreenState extends State<VerifyPhoneNumberScreen>
292292 return SafeArea(
293293 child: FirebasePhoneAuthHandler(
294294 phoneNumber: widget.phoneNumber,
295- signOutOnSuccessfulVerification: false, // default
296- linkWithExistingUser: false, // default
295+ signOutOnSuccessfulVerification: false,
296+ linkWithExistingUser: false,
297297 autoRetrievalTimeOutDuration: const Duration(seconds: 60),
298298 otpExpirationDuration: const Duration(seconds: 60),
299299 onCodeSent: () {
@@ -321,11 +321,33 @@ class _VerifyPhoneNumberScreenState extends State<VerifyPhoneNumberScreen>
321321 );
322322 },
323323 onLoginFailed: (authException, stackTrace) {
324- showSnackBar('Something went wrong!');
325- log(VerifyPhoneNumberScreen.id, error: authException.message);
326- // handle error further if needed
324+ log(
325+ VerifyPhoneNumberScreen.id,
326+ msg: authException.message,
327+ error: authException,
328+ stackTrace: stackTrace,
329+ );
330+
331+ switch (authException.code) {
332+ case 'invalid-phone-number':
333+ // invalid phone number
334+ return showSnackBar('Invalid phone number!');
335+ case 'invalid-verification-code':
336+ // invalid otp entered
337+ return showSnackBar('The entered OTP is invalid!');
338+ // handle other error codes
339+ default:
340+ showSnackBar('Something went wrong!');
341+ // handle error further if needed
342+ }
327343 },
328344 onError: (error, stackTrace) {
345+ log(
346+ VerifyPhoneNumberScreen.id,
347+ error: error,
348+ stackTrace: stackTrace,
349+ );
350+
329351 showSnackBar('An error occurred!');
330352 },
331353 builder: (context, controller) {
@@ -412,11 +434,14 @@ class _VerifyPhoneNumberScreenState extends State<VerifyPhoneNumberScreen>
412434 if (hasFocus) await _scrollToBottomOnKeyboardOpen();
413435 },
414436 onSubmit: (enteredOtp) async {
415- final isValidOtp =
437+ final verified =
416438 await controller.verifyOtp(enteredOtp);
417- // Incorrect OTP
418- if (!isValidOtp) {
419- showSnackBar('The entered OTP is invalid!');
439+ if (verified) {
440+ // number verify success
441+ // will call onLoginSuccess handler
442+ } else {
443+ // phone verification failed
444+ // will call onLoginFailed or onError callbacks with the error
420445 }
421446 },
422447 ),
0 commit comments