I am using this plugin for phone authentication.https://ionicframework.com/docs/native/firebase-authentication
I have successfully sent the top to mobile numbers, but while retrieving I am getting following error every time
The SMS code has expired. Please re-send the verification code to try again
I also want to auto verify otp(without letting the user to manually enter otp).
I think both issues are interconnected
Here is my code
import { AngularFireAuth } from '@angular/fire/auth';
import * as firebase from 'firebase/app';
import { FirebaseAuthentication } from '@ionic-native/firebase-authentication/ngx';
constructor(private router: Router,private fireAuth: AngularFireAuth,public firebaseAuthentication : FirebaseAuthentication) {}
send(){
this.firebaseAuthentication.verifyPhoneNumber("+91xxxxxxxxxx", 30000).then(credential => {
alert("code sent")
console.log(credential)
if(credential) {
this.verificationid = credential
const smsCode = prompt("Enter SMS verification code");
let cred = firebase.auth.PhoneAuthProvider.credential(this.verificationid,smsCode)
this.fireAuth.signInWithCredential(cred).then(val => {
console.log(val)
console.log("successs")
}).catch(err => console.log(err))
}
})
}