4

I am trying to use react-native-firebase to do Phone Auth. Firebase is correctly set-up. I can get SMS code back for some phone numbers. I am using verifyPhoneNumber method. My code looks like this:

firebase
      .auth()
      .verifyPhoneNumber(phoneNumber)
      .on('state_changed', phoneAuthSnapshot => {
        console.log(phoneAuthSnapshot);
        switch (phoneAuthSnapshot.state) {

phoneAuthSnapshot contains below:

{verificationId: null, code: null, error: null, state: "verified"}

Now, since both verificationId and code are NULL, I cannot build credentials:

const credential = firebase.auth.PhoneAuthProvider.credential(
  verificationId,
  codeInput
);

Since, I cannot build credentials, I cannot get the user details:

firebase
  .auth()
  .signInWithCredential(credential)
  .then(user => {
    console.log('PHONE AUTH USER ->>>>>', user.toJSON());
    this.setState({ user: user.toJSON() });
  })

How can I resolve this?

halfer
  • 19,824
  • 17
  • 99
  • 186
Vikalp Jain
  • 583
  • 2
  • 11
  • 25

0 Answers0