React-native-firebase: error.credential is null if credential-already-in-use

Created on 23 Jul 2018  路  4Comments  路  Source: invertase/react-native-firebase

Summary:

According to the docs, if the linkWithCredential fails, then the error should contain error.credential which should be used in the subsequent call to signInWithCredential, but it's null.

Quoted from the docs:

auth/credential-already-in-use: Thrown if the account corresponding to the credential already exists among your users, or is already linked to a Firebase User. For example, this error could be thrown if you are upgrading an anonymous user to a Google user by linking a Google credential to it and the Google credential used is already associated with an existing Firebase Google user. The fields error.email, error.phoneNumber, and error.credential (AuthCredential) may be provided, depending on the type of credential. You can recover from this error by signing in with error.credential directly via auth#signInWithCredential.

I'm using phone auth with anonymous login. So all users are authenticated anonymously at first, and during login, are linked with the credentials created using phone number and sms code. This works fine for new mobile numbers, however when the mobile number already exists, the linking fails, and I've to signInWithCredential instead, which is not possible at the moment, because the error.credential is null.

Any help is appreciated,
Thanks,

Android iOS Authentication

Most helpful comment

Hey, not forgotten about this - I've been working on adding support in React Native for the second issue I mentioned above.

Have just sent up a PR to React Native - so once/if this lands in a version we can start getting this supported.

PR: https://github.com/facebook/react-native/pull/20940


Loving react-native-firebase and the support we provide? Please consider supporting us with any of the below:

All 4 comments

@barbarosh the problem at the moment is that PhoneAuthCredentials aren't serializable both ways across the bridge, at least not on Android - @sowdri and I discussed this at length on the #authentication discord channel. We need to come up with a way of storing the token on the native side only and faking it on the JS side - with the real credential staying on native until it's consumed.

The second bigger issue is that React Native errors (through promise rejections on native code) can only provide string code and message properties - you cannot add extra properties, in this case, a credential or something referencing one, so we'd have to make all auth methods resolve for everything (even on exceptions) and and add code to detect if resolved data was an error or not in JS code, convert to a JS error and finally JS promise resolve/reject to userlands code - based on natives resolved value. Quite a big internal change.


Loving react-native-firebase and the support we provide? Please consider supporting us with any of the below:

Hey, not forgotten about this - I've been working on adding support in React Native for the second issue I mentioned above.

Have just sent up a PR to React Native - so once/if this lands in a version we can start getting this supported.

PR: https://github.com/facebook/react-native/pull/20940


Loving react-native-firebase and the support we provide? Please consider supporting us with any of the below:

Hey, closing this and tracking in the following PR:

https://github.com/invertase/react-native-firebase/pull/2107

Thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dgruseck picture dgruseck  路  3Comments

NordlingDev picture NordlingDev  路  3Comments

Draccan picture Draccan  路  3Comments

joecaraccio picture joecaraccio  路  3Comments

alizahid picture alizahid  路  3Comments