tengo un login donde inician mediante facebook. Quiero agregar la opción de iniciar sesión mediante Twitter. Pero para eso tambien debo ser capaz de manejar errores con cuentas que tienen el mismo correo que ya hayan sido registradas antes. Es decir, si un usuario se registra con facebook con el correo [email protected] y luego quiere entrar con twitter con el correo [email protected]. Debo detectar eso y manejarlo. La documentación da como ejemplo este código:
// Step 1.
// User tries to sign in to Twitter.
auth.signInWithPopup(new firebase.auth.TwitterAuthProvider()).catch(function(error) {
// An error happened.
if (error.code === 'auth/account-exists-with-different-credential') {
// Step 2.
// User's email already exists.
// The pending Twitter credential.
var pendingCred = error.credential;
// The provider account's email address.
var email = error.email;
// Get registered providers for this email.
auth.fetchProvidersForEmail(email).then(function(providers) {
// Step 3.
// If the user has several providers,
// the first provider in the list will be the "recommended" provider to use.
if (providers[0] === 'password') {
// Asks the user his password.
// In real scenario, you should handle this asynchronously.
var password = promptUserForPassword(); // TODO: implement promptUserForPassword.
auth.signInWithEmailAndPassword(email, password).then(function(user) {
// Step 4a.
return user.link(pendingCred);
}).then(function() {
// Twitter account successfully linked to the existing Firebase user.
goToApp();
});
return;
}
// All the other cases are external providers.
// Construct provider object for that provider.
// TODO: implement getProviderForProviderId.
var provider = getProviderForProviderId(providers[0]);
// At this point, you should let the user know that he already has an account
// but with a different provider, and let him validate the fact he wants to
// sign in with this provider.
// Sign in to provider. Note: browsers usually block popup triggered asynchronously,
// so in real scenario you should ask the user to click on a "continue" button
// that will trigger the signInWithPopup.
auth.signInWithPopup(provider).then(function(result) {
// Remember that the user may have signed in with an account that has a different email
// address than the first one. This can happen as Firebase doesn't control the provider's
// sign in flow and the user is free to login using whichever account he owns.
// Step 4b.
// Link to Twitter credential.
// As we have access to the pending credential, we can directly call the link method.
result.user.link(pendingCred).then(function() {
// Twitter account successfully linked to the existing Firebase user.
goToApp();
});
});
});
}
});
Mi problema está en esta parte:
var provider = getProviderForProviderId(providers[0]);
auth.signInWithPopup(provider).then(function(result) {
El navegador me dice:
getProviderForProviderId" is not defined
No se que debo hacer con las 2 lineas anteriores.