0

I am trying to send OTP using react-native firebase .Initially it was send otp but from couple of days it throws an un-understandable error when i send OTP using following code.

  const [user, setData] = useState(null);


  useEffect(async () => {
    const subscriber = auth().onAuthStateChanged(async user => {
      try {
        if (user) {
          console.log({user});
          console.log(user._verificationId);
          await _storeData('user_info', JSON.stringify({phone, ui: user.uid}));
          navigation.navigate('App');
        } else {
          await sendOTP();
        }
      } catch (error) {
        console.log('error in saving data to async', error);
      }
    });
  }, []);
  // send OTP to phone
  const sendOTP = async () => {
    try {
      console.log(' <<<<<<sending OTP to phone>>>>>> ');
 
      const confirmation = await auth().signInWithPhoneNumber(phone);
      alert(JSON.stringify(confirmation));
      setConfirm(confirmation);
      console.log({confirmation});
    } catch (error) {
      console.log(JSON.stringify(error));
    }
  };

  //

  // verify OTP here
  async function confirmCode() {
    try {
     
      if (!user) {
        const userProfile = await confirm.confirm(code);
        await _storeData(
          'user_info',
          JSON.stringify({phone, uid: userProfile._verificationId}),
        );
   
        navigation.navigate('App');
      }
    } catch (error) {
    
      showToast('Invalid code.');
      console.log('Invalid code.');
    }
  }

The code was working fine initially but now it throws following message in console : {"line":6576,"column":64,"sourceURL":"http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.medicineecommerce&modulesOnly=false&runModule=true"} enter image description here

  • Calling `JSON.stringify()` on an error loses much of the information about the error. Take a look at what happens if you execute this in a REPL: `console.log(JSON.stringify(new RangeError('foo'))); // output: {}` Instead, log the error as it was given or with `error.toString()`. Alternatively, take a look at this question, [Is it not possible to stringify an error using JSON.stringify?](https://stackoverflow.com/questions/18391212/is-it-not-possible-to-stringify-an-error-using-json-stringify), for alternatives to convert to a JSON string. – j1mbl3s Jun 20 '21 at 12:02

0 Answers0