loginWithPhoneVerifyCode method

  1. @override
Future<Either<PhoneAuthError, bool>> loginWithPhoneVerifyCode(
  1. String smsCode
)
override

Implementation

@override
Future<Either<PhoneAuthError, bool>> loginWithPhoneVerifyCode(String smsCode) async {
  try {
    // Create a PhoneAuthCredential with the verification ID and the SMS code
    PhoneAuthCredential credential = PhoneAuthProvider.credential(
      verificationId: _phoneVerificationId,
      smsCode: smsCode,
    );

    // Sign in the user with the credential
    await _fbAuth.signInWithCredential(credential);

    return right(true);
  } on FirebaseAuthException catch (e) {
    if (e.code == 'invalid-verification-code') {
      return left(PhoneAuthError.wrongSmsCode);
    } else if (e.code == 'session-expired') {
      return left(PhoneAuthError.smsCodeExpired);
    } else if (e.code == 'invalid-verification-id') {
      return left(PhoneAuthError.sessionExpired);
    } else if (e.code == 'user-not-found') {
      return left(PhoneAuthError.invalidPhone);
    } else {
      logd(
          'e.code was something unhandled in loginWithPhoneVerifyCode:${e.message ?? 'no message'}');
      return left(PhoneAuthError.unexpected);
    }
  } catch (e) {
    loge(e);
    return left(PhoneAuthError.unexpected);
  }
}