kofifus kofifus - 8 months ago 741
Javascript Question

signInWithEmailAndPassword and EmailAuthProvider

I am trying to understand the new authentication model. I am trying to convert web code that used the older authWithPassword.

Considering I had:

firebase.authWithPassword({email: email, password: password }).then(
authData => console.log('auth: authWithPassword success '+authData.uid),
err => console.log('auth: authWithPassword fail: '+err));

How do I achieve the same thing with the new version ?

There seem to be two different interfaces:




but I don't understand the difference or how to use them. Is there any clear example for the correct way to do email authentication ?


There are a lot of such differences with the new API. Best to stick closely to the docs.

The new docs site has a guide on email/password authentication, but to your specific question about the code:

firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
  // Handle Errors here.
  var errorCode = error.code;
  var errorMessage = error.message;
  // ...

Source: https://firebase.google.com/docs/auth/web/password-auth#sign_in_a_user_with_an_email_address_and_password