简体   繁体   中英

React native firebase phone authentication, if code sent navigate to otp screen

I am using react native firebase, if code sent then i want to navigate to otp screen

But it shows an warning :

Non-serializable values were found in the navigation state. Check:

OtpVerification > params.confirm._auth._app._deleteApp (Function)

This can break usage such as persisting and restoring state. This might happen if you passed non-serializable values such as function, class instances etc. in params. If you need to use components with callbacks in your options, you can use 'navigation.setOptions'

My code :

In login Screen :

async function signInWithPhoneNumber(phoneNumber) {
try {
  const confirmation = await auth().signInWithPhoneNumber(phoneNumber);

  props.navigation.navigate('OtpVerification', {
    confirm: confirmation,
    phoneNo,
  });
} catch (error) {
  console.log(error);
}

}

In Otp Screen :

async function confirmCode() {
if (otp) {
  try {
    await confirm.confirm(otp);
    props.navigation.navigate('OnBoarding');
  } catch (error) {
    AlertMsg('Invalid OTP');
  }
} else {
  AlertMsg('Please Enter OTP');
}

}

So I believe in belive function where you have confirmation variable, You might have to pass some constant value over there handling the return of firebase signin.

async function signInWithPhoneNumber(phoneNumber) {
try {
  const confirmation = await auth().signInWithPhoneNumber(phoneNumber);

  props.navigation.navigate('OtpVerification', {
    confirm: confirmation,
    phoneNo,
  });
} catch (error) {
  console.log(error);
}

Check this document - https://reactnavigation.org/docs/troubleshooting/#i-get-the-warning-non-serializable-values-were-found-in-the-navigation-state

This expo for your navigation - https://snack.expo.dev/vKpugczaG

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM