Update Phone Number in Firebase Authentication - R

2020-02-02 03:35发布

问题:

I have a screen it's a settings screen and I have an input that's for update data,

so I want to update the signed phone number how can I achieve it? and how i get the credential?

here's my code i used react-native-firebase v6+

import auth from '@react-native-firebase/auth';

 const updateMobile = async () => {
    await auth().currentUser.updatePhoneNumber(credential =>
      console.log(credential)
    );
  };

When i call this function i got this error

Attempt to invoke virtual method "boolean java.lang.String.equals(java.lang.Object)" on an null object referance

UPDATE

I read a Docs and I get the credential like this, But i have an error , I dont know who's bind -_-

Possible Unhandled Promise Rejection (id: 2): TypeError: Cannot read property 'bind' of undefined

=====

When i delete await in const snapshot = auth() .verifyPhoneNumber(mobile) the error go away but i see a new error

Error: [auth/invalid-credential] The supplied auth credential is malformed, has expired or is not currently supported.

  const updateMobile = async () => {
    const snapshot = await auth()
      .verifyPhoneNumber(mobile)
      .on('state_changed', phoneAuthSnapshot => {
        console.log('Snapshot state: ', phoneAuthSnapshot.state);
      });
    const credential = auth.PhoneAuthProvider.credential(
      snapshot.verificationId,
      snapshot.code,
    );
    console.log('credential', credential);
    await auth().currentUser.updatePhoneNumber(credential);
  };