React-native-firebase: 馃敟 [v6] Casting error from JS to native when calling auth().verifyPhoneNumber(phoneNumber)

Created on 26 Sep 2019  路  11Comments  路  Source: invertase/react-native-firebase


Issue



When calling auth().verifyPhoneNumber(phoneNumber) I get the following error:
java.lang.Double cannot be cast to java.lang.String

I traced the error back and I think it's in this line PhoneAuthListener.js#L53 where the this._phoneAuthRequestId is passed as number but the method in java ReactNativeFirebaseAuthModule.java#L980 is expecting it as string

Currently I patched the code locally by converting the this._phoneAuthRequestId to string before passing it to the native java method


Project Files






iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like:

# N/A
#### `AppDelegate.m`:
// N/A


Android

Click To Expand

#### Have you converted to AndroidX? - [x] my application is an AndroidX application? - [x] I am using `android/gradle.settings` `jetifier=true` for Android compatibility? - [x] I am using the NPM package `jetifier` for react-native compatibility? #### `android/build.gradle`:

// N/A
#### `android/app/build.gradle`:
// N/A
#### `android/settings.gradle`:
// N/A
#### `MainApplication.java`:
// N/A
#### `AndroidManifest.xml`:
<!-- N/A -->


Environment

Click To Expand

**`react-native info` output:**

System:
    OS: Windows 10
    CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
    Memory: 4.47 GB / 11.87 GB
  Binaries:
    Node: 10.16.2 - C:\Users\Ali\AppData\Local\Temp\yarn--1569487673189-0.21848002575558767\node.CMD
    Yarn: 1.17.3 - C:\Users\Ali\AppData\Local\Temp\yarn--1569487673189-0.21848002575558767\yarn.CMD
    npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD
  IDEs:
    Android Studio: Version  3.5.0.0 AI-191.8026.42.35.5791312
- **Platform that you're experiencing the issue on**: - [ ] iOS - [ ] Android - [ ] **iOS** but have not tested behavior on Android - [x] **Android** but have not tested behavior on iOS - [ ] Both - **`react-native-firebase` version you're using that has this issue:** - `6.0.0` - **`Firebase` module(s) you're using that has the issue:** - `Auth` - **Are you using `TypeScript`?** - `Y`




Think react-native-firebase is great? Please consider supporting all of the project maintainers and contributors by donating via our Open Collective where all contributors can submit expenses. [Learn More]

Bug Android iOS Authentication >= 6

Most helpful comment

@yogeshkotadiya have pushed up a change above to fix that, will be there in the next release this week.

All 11 comments

I can confirm this bug on v6, It's working on v5.

Anyone care to PR the change and/or share a patch-package patch file for others?

It happens on iOS as well. Got this error

JSON value '0' of type NSNumber cannot be converted to NSString

PhoneAuthListener.js

if (isIOS) {
  this._auth.native.verifyPhoneNumber(phoneNumber, this._phoneAuthRequestId);
}

RCT_EXPORT_METHOD(verifyPhoneNumber:
  (FIRApp *) firebaseApp
    :(NSString *) phoneNumber
    :(NSString *) requestKey
) {
}

Thanks for the extra information @r0b0t3d

I need a quick fix for that so I patched it locally by converting this._phoneAuthRequestId to a string.
There is a second problem though: When the verification fails and triggers _verificationFailedHandler it uses NativeFirebaseError which is undefined.
https://github.com/invertase/react-native-firebase/blob/1f2ee86d8063654a2ad9818a736e7bde46efe0d4/packages/auth/lib/PhoneAuthListener.js#L174

Hey 馃憢 this issue should now be fixed in v6.0.1, thanks. release notes

After updating to 6.0.1, I'm getting this error

try {
    const { code } = await auth().verifyPhoneNumber(phoneNumber)
} catch (error){
    console.log(error) // [TypeError: undefined is not an object (evaluating 'this._promise.then.bind')]
}

Screenshot_1570612120

@yogeshkotadiya have pushed up a change above to fix that, will be there in the next release this week.

@Salakar Thanks for the quick patch but now verifyPhoneNumber Promise does not resolve or rejects phoneAuthSnapShot.

This is the error I'm getting,

[TypeError: undefined is not an object (evaluating 'this._promise.then.bind')]

Currently, the only way to access phoneAuthSnapShot is by using .on.

I want to use async/await.

try {
    const { code } = await auth().verifyPhoneNumber(phoneNumber)
} catch (error){
    console.log(error) // [TypeError: undefined is not an object (evaluating 'this._promise.then.bind')]
}

https://github.com/invertase/react-native-firebase/blob/c518bb6e6f7232cc84f666964cdd8726f885bb77/packages/auth/lib/PhoneAuthListener.js#L213-L227

Hi everyone,
Some news for this issue ?
Thanks

Fix is now live in v6.0.4. Thanks

Was this page helpful?
0 / 5 - 0 ratings