简体   繁体   中英

firebase phone auth doesn't resend code [React Native]

I'm using react native firebase phone auth and it worked for the first time. but i can't seem to resend OTP code when i try to signInWithPhoneNumber with that number for the second time,third time and so on

在此处输入图片说明

firebase automatically assumes that number has already signed in. That number is there on the firebase console But i havent verified the OTP code at all.

I tried deleting that number from the console and do signInWithPhoneNumber again but the result stills the same :

As far as i know that if you try to signInWithPhoneNumber or verifyPhoneNumber, firebase will resend the OTP code ?

Where did i do wrong?

在此处输入图片说明

Two things may be happening here:

  • You probably set the timeout too high when setting up Phone verification
  • You may have not set a flag that phone verification is in progress

You can see more of that in Firebase Phone Authentication documentation :

The verifyPhoneNumber method is reentrant: if you call it multiple times, such as in an activity's onStart method, the verifyPhoneNumber method will not send a second SMS unless the original request has timed out.

You can use this behavior to resume the phone number sign in process if your app closes before the user can sign in (for example, while the user is using their SMS app). After you call verifyPhoneNumber, set a flag that indicates verification is in progress. Then, save the flag in your Activity's onSaveInstanceState method and restore the flag in onRestoreInstanceState. Finally, in your Activity's onStart method, check if verification is already in progress, and if so, call verifyPhoneNumber again. Be sure to clear the flag when verification completes or fails (see Verification callbacks).

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