Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

297
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

about 4 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 Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!