Skip to content

[🐛] Bug Report Title - OTP verification fails on Android 13+ with "OTP expired" error #8441

Open
@Vikalp-cloudactivelabs

Description

@Vikalp-cloudactivelabs

Issue
I am facing an issue with OTP verification using @react-native-firebase/auth. On Android 13+, OTP verification fails with an "OTP expired" error even when entered correctly. However, it works fine on Android 11.

Steps to Reproduce

  1. Use auth().signInWithPhoneNumber(phoneNumber, false) on an Android 13+ device.
  2. Receive the OTP on the same device.
  3. Enter the OTP and attempt verification.
  4. The verification fails with the error "OTP expired".

Expected Behavior
The OTP should be verified successfully if entered within the valid time frame.

Actual Behavior

  • OTP fails to verify with an "OTP expired" error on Android 13+.
  • Works fine on Android 11.

Code Snippet

const MobileAuthentication = async () => {
  if (!mobileNumber) {
    Alert.alert('Error', 'Please enter a mobile number');
    return;
  }
  if (mobileNumber.length !== 10) {
    Alert.alert('Error', 'Please enter a 10-digit mobile number');
    return;
  }

  setIsLoading(true);

  try {
    const formattedPhoneNumber = `+${countryCode}${mobileNumber}`;
    setPhoneNumber(formattedPhoneNumber);
    let confirmation= await auth().signInWithPhoneNumber(formattedPhoneNumber);

    setConfirm(confirmation);
    setShowVerify(true);
    setTimer(30);
    setIsResendDisabled(true);
    setIsLoading(false);
  } catch (error) {
    console.error(error);
    alert(error);
    setIsLoading(false);
  }
};

const verify = useCallback(async () => {
  try {
    setIsLoading(true);
    if (otpValues.join('').length === 6) {
      const otp = otpValues.join('');
      const userCredential = await confirm.confirm(otp);
      const idToken = await userCredential.user.getIdToken();

      if (idToken) {
        await verifyOtp({
          variables: {
            token: idToken,
            phone: phoneNumber,
            deviceId,
          },
        });
      } else {
        setIsLoading(false);
        alert('User authentication failed. Please try again.');
      }
    } else {
      setIsLoading(false);
      alert('Enter full OTP');
    }
  } catch (error) {
    setIsLoading(false);
    console.log('error', error);
    alert(error);
  }
}, [confirm, otpValues, phoneNumber, deviceId]);

Project Files
package.json:

{
  "@react-native-firebase/app": "^21.13.0",
  "@react-native-firebase/auth": "^21.13.0"
}

Image

React Native Version: (Provide your version)
Android Version:

✅ Android 13+ (Issue Occurs)

✅ Android 11 (Works Fine)
Device Tested On: (e.g., Pixel 7, Samsung Galaxy S23)

Additional Context
Using forceRecaptcha=false to avoid reCAPTCHA flow.

OTP is received but always fails with "OTP expired".

No issues observed on Android 11 or below.

Firebase authentication settings appear to be configured correctly.

Possible Workarounds Tried
Enabling/disabling forceRecaptcha.

Trying different phone numbers.

Checking Firebase settings—no unusual behavior observed.

Would appreciate any insights on whether this is an issue with Firebase or if there’s a workaround! 🚀

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions