singInWithOTP method

Future<bool> singInWithOTP(
  1. String otp, {
  2. dynamic onError(
    1. dynamic e
    )?,
})

Implementation

Future<bool> singInWithOTP(
  String otp, {
  Function(dynamic e)? onError,
}) async {
  if (_verificationId == null) return false;
  if (this is FakeLoginMixin) {
    bool isFakeLogin = otp == '123456' &&
        (this as FakeLoginMixin).fakePhones.contains(Common.phoneNumberInput);
    if (isFakeLogin) {
      if (kDebugMode) {
        print('================');
        print('|| fake login ||');
        print('================');
      }
      return true;
    }
  }
  var credential = PhoneAuthProvider.credential(
    verificationId: _verificationId!,
    smsCode: otp,
  );
  try {
    await FirebaseAuth.instance.signInWithCredential(credential);
    User? user = FirebaseAuth.instance.currentUser;
    if (user != null) {
      await initAccountFirebase(phone: user.phoneNumber!, uidPhone: user.uid);
      if (this is SQLLoginMixin) {
        await (this as SQLLoginMixin)
            .initAccountSQL(phone: user.phoneNumber!, uidPhone: user.uid);
      }
      return true;
    }
    return false;
  } catch (e) {
    if (onError != null) {
      onError(e);
    } else {
      handelException(e, subTitle: 'singInWithOTP');
    }
    return false;
  }
}