I am trying to resend verification code, but I couldn't find a good way.
If the first time I authenticate a number I receive verification code.
but in the next time, if I authenticate the same number I am not able to get verification code. even I delete the phone number from firebase but still I couldn't resend the verification code.
Why I need this?
Because someone may remove my app, but after a period of time he/she maybe install again my app, so he/she should be able to get a verification code again by the number he/she registed in firebase before.
Or maybe because of some problem someone doesnt receive verification code for the first time, so he/she should be able to resend the code.
signIn = async phone => {
try {
const confirmResult = await firebase.auth().signInWithPhoneNumber(phone);
this.setState({ confirmResult });
} catch (error) {
console.log(error);
}
}
confirmCode = async () => {
try {
const { receivedcode, confirmResult } = this.state;
if (confirmResult && receivedcode.length) {
const user = await confirmResult.confirm(receivedcode);
if(user) console.log(user);
}
} catch (e) {
console.log(e);
}
}
I re-trigger SMS code in my app like so
firebase
.auth()
.verifyPhoneNumber(phoneNumber)
.on(
'state_changed',
async phoneAuthSnapshot => {
...
...
(if it works I linkUser etc - my primary method is email)
Hello @mikehardy, unfortunately didnt work for me
I get on console the below:
auto verified on android
{ verificationId: null,
code: null,
error: null,
state: 'verified' }
{ verificationId: null,
code: null,
error: null,
state: 'verified' }
Is there a way to unverify a phone number this may help us to resend a code
Strange - I don't have a lot of experience here. Perhaps you need to unlink first, or use an admin API to purge verification (the only way I know of)? I am only brainstorming here to help tests, I have not done it myself.
Ok thank you, I hope I find a solutions for this, I am really stucked with this
@Salakar any help on this issue, please.
firebase.auth().signInWithPhoneNumber(phone, true);
forceResend also does not work.
@muhammadwfa please respect we can't instantly reply to issues.
If the users device is already authenticated, what use case do you need to resend the message? Are you sure the device isn't just automatically handling the message so the user never sees it?
Hello @Ehesp , thank you to reply and I am sorry to my hurry.
Why I need to Resend the SMS code.
I know at the first time user get the SMS code, and it works pretty well, but where is my concern. In some cases maybe a user delete the App immediately after the first install.
And one hour later or one day later he/she maybe return back the App with same phone number for the second time.
There is that he/she will not receive SMS code. and he/she without sms code, will be logged in.
Like whatsapp, imo, viber, every time a user re-install it with same phone number they receive SMS code for every re-installation.
I've had a look around and there doesn't seem to be a way to "remove" the authorisation. I'm not sure there's much we can do about this. I'll take a look into the force resend logic to see if something is going on there, but I won't be able to look at that as a priority, so if you could help debug that'd help.
OK thank you, Hope to find a solution.
Hi @mikehardy, thank you the code you provided now is working well to resend the code.
But could you please let me know how Do i confirm it?
The firebase.auth().signInWithPhoneNumber(phone)
returns a confirmResut which help us to confirm the SMS code.
Now how to confirm SMS code we get with firebase.auth().verifyPhoneNumber(phone)
?
I'm using the code provided as an example https://rnfirebase.io/docs/v5.x.x/auth/reference/auth - whatever it does, I do - sounds like this issue is solved though (re-sending) so I'll close this one
@muhammadwfa @mikehardy I am still struggling with how to resend code. Mind Putting up a sample code to see how to resend. I have tried to set the forceResend too true. But still the state is still showing 'Verified".
firebase.auth().signInWithPhoneNumber(phone, true);
the above doesn't work and this:
firebase
.auth()
.verifyPhoneNumber(phoneNumber)
.on(
'state_changed',
async phoneAuthSnapshot => {
...
...
didn't work either..
Most helpful comment
I re-trigger SMS code in my app like so
(if it works I linkUser etc - my primary method is email)