Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔥 [v6] Casting error from JS to native when calling auth().verifyPhoneNumber(phoneNumber) #2639

Closed
5 of 10 tasks
Ali-Nahhas opened this issue Sep 26, 2019 · 11 comments · Fixed by #2828
Closed
5 of 10 tasks
Assignees
Milestone

Comments

@Ali-Nahhas
Copy link

Ali-Nahhas commented Sep 26, 2019

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
  • I'm using Pods and my Podfile looks like:
# N/A

AppDelegate.m:

// N/A


Android

Click To Expand

Have you converted to AndroidX?

  • my application is an AndroidX application?
  • I am using android/gradle.settings jetifier=true for Android compatibility?
  • 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
    • 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]

@yogeshkotadiya
Copy link

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

@mikehardy
Copy link
Collaborator

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

@mikehardy mikehardy changed the title 🔥 Casting error from JS to native when calling auth().verifyPhoneNumber(phoneNumber) 🔥 [v6] Casting error from JS to native when calling auth().verifyPhoneNumber(phoneNumber) Sep 27, 2019
@r0b0t3d
Copy link
Contributor

r0b0t3d commented Sep 28, 2019

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
) {
}

@mikehardy
Copy link
Collaborator

Thanks for the extra information @r0b0t3d

@Salakar Salakar added this to the v6.1.0 milestone Oct 1, 2019
@pierregoutheraud
Copy link

pierregoutheraud commented Oct 2, 2019

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.

snapshot.error = new NativeFirebaseError({ userInfo: state.error }, null, 'auth');

@Salakar
Copy link
Member

Salakar commented Oct 7, 2019

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

@yogeshkotadiya
Copy link

yogeshkotadiya commented Oct 9, 2019

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

Salakar added a commit that referenced this issue Oct 9, 2019
@Salakar
Copy link
Member

Salakar commented Oct 9, 2019

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

@yogeshkotadiya
Copy link

@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')]
}

then(fn) {
this._promiseDeferred();
if (this._promise) {
return this._promise.then.bind(this._promise)(fn);
}
return undefined;
}
catch(fn) {
this._promiseDeferred();
if (this._promise) {
return this._promise.catch.bind(this._promise)(fn);
}
return undefined;
}

@Salakar Salakar reopened this Oct 9, 2019
@adrienbkr
Copy link

adrienbkr commented Nov 4, 2019

Hi everyone,
Some news for this issue ?
Thanks

MBagory added a commit to MBagory/react-native-firebase that referenced this issue Nov 5, 2019
Salakar pushed a commit that referenced this issue Nov 6, 2019
@Salakar
Copy link
Member

Salakar commented Nov 17, 2019

Fix is now live in v6.0.4. Thanks

androidIsForVivek pushed a commit to androidIsForVivek/react-native-firebase that referenced this issue Sep 15, 2021
androidIsForVivek pushed a commit to androidIsForVivek/react-native-firebase that referenced this issue Sep 15, 2021
androidIsForVivek pushed a commit to androidIsForVivek/react-native-firebase that referenced this issue Sep 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants