I have implemented emailpassword, google and facebook sign in on my web app. But in previous version phone based signin was also there which I had to remove. So I want the previous users to be linked with other options.
I am trying to link phone number to password based account.
Below code is working and the linking is working perfectly but the problem is I want the user to be signed in with password based account and not the phone number based.
Below is the error that I am getting.
signInWithCredential failed: First argument "credential" must be a valid credential.'
async function codeVerification(verificationId, verificationCode){
try {
const credential = firebase.auth.PhoneAuthProvider.credential(verificationId, verificationCode)
const prevUser = auth.currentUser;
// prevUser.linkWithCredential(credential);
auth.signInWithCredential(credential)
.then(user => {
const secondUser = user.credential;
auth.currentUser.delete()
.then(() => {
return prevUser.linkWithCredential(credential);
})
.then(() => {
console.log(secondUser);
auth.signInWithCredential(secondUser);
//this is the step where I am getting error I guess, because I am signing in with phonenumber but how to store current credentials of user
})
});
} catch (error) {
}
}
I want the user to be signin with the password based account only not with the phone number. How can I implement this correctly?
Thanks