• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

249
Views
Firebase : Not able to link phone number with other AuthProviders javascript

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.

enter image description here

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.

enter image description here 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

almost 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error