0
votes

I am implementing firebase phone number authentication in React Native app. I am following this documentation: https://invertase.io/oss/react-native-firebase/v6/auth/phone-auth

This successfully runs:

const {confirm} = await firebase.auth().signInWithPhoneNumber(value);
this.setState({confirm})
console.log(confirm)     // is a function

Now when I run confirm(code):

    try {
      await this.state.confirm('123456');
      // Successful login - onAuthStateChanged is triggered
    } catch (e) {
      console.error(e); // Invalid code
    }

It gives the following error: TypeError: Cannot read property 'native' of undefined.

I have searched a lot, but couldn't solve it. Please help. Error Screen

2

2 Answers

1
votes

Please do like something

this.state = {confirmResult: null};

Then

const confirmResult = await firebase.auth().signInWithPhoneNumber(value);
this.setState({confirmResult});

And Then

const { confirmResult } = this.state;

try {
   await confirmResult.confirm('123456');
   // Successful login - onAuthStateChanged is triggered
} catch (e) {
   console.error(e); // Invalid code
}
0
votes

You have now assigned a function from a variable but are running it from a status value. Run on a variable.

try {
  await confirm('123456'); // User entered code
  // Successful login - onAuthStateChanged is triggered
} catch (e) {
  console.error(e); // Invalid code
}