Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

125
Visualizações
How to switch between emailLink and password sign-in method in firebase auth?

There are two methods a user can sign in via email: "emailLink" and "password" (see https://firebase.google.com/docs/auth/web/email-link-auth#differentiating_emailpassword_from_email_link)

I want to give my users the option to switch between these two methods. However, I did not find any documentation to how I could unlink an email sign-in method (e.g. password).

As far as I understood, you can only unlink a sign-in method when the user has multiple provider IDs, but email-link and password share the same providerId (strangely emailLink providerID is called "password").

Thanks for your help!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

EDIT

When switching from emailLink to password, a major flaw with the solution below is that after the switch the email won't be verified anymore. So in this case, it is better to call updatePassword. This will result the user having two email sign ins, "password" and "emailLink" (as returned by fetchSignInMethodsForEmail). When the user switches back to "emailLink", you can use the solution below and the result of fetchSignInMethodsForEmail will only include "emailLink".


So I found the solution: If you switch from emailLink to password, you simply use the following:


// 1) get credential from use input
const credential = EmailAuthProvider.credential(email, newPassword)
// 2) unlink email link authentication
// https://firebase.google.com/docs/auth/web/account-linking#unlink-an-auth-provider-from-a-user-account
const newUser = await unlink(currentUser, "password")
// 3) link with new credential
const userCredential = await linkWithCredential(newUser, credential)

Now, if we want to switch back from password to emailLink, we first have to send the client an email containing the sign in link. Once the user clicks on the sign in link, we again create the credential and proceed in the same manner.

Note that if there goes something wrong between step 2 and 3, the user is pretty much screwed and we have to take special care of that scenario.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda