Skip to content
Advertisement

DId firebase createUserWithEmailAndPassword() change the return value?

I have been using this code for a year now:

firebase.auth().createUserWithEmailAndPassword(textUser, textPassword)
.then(function(user){
  console.log('uid',user.uid)

  //Here if you want you can sign in the user
}).catch(function(error) {
    //Handle error
});

However I had complaints over the last 2 days of new users having trouble creating a new login. I checked the “user” variable in this code and it looked like this:

{
  additionalUserInfo: {
    providerId: "password", 
    isNewUser: true 
  },
  credential: null,
  operationalType:"signIn"

  user: {
    (bunch of fields...)
    uid: "xxxxx123456789",
    (bunch of fileds...)
  }
}

Which means that I now have to refer to uid by using user.user.uid instead of user.uid. I made this change and the code works but I have several other uses of this function and I’m wondering if this is an actual change or if I’m seeing something unusual. I have not changed this code in ages so I’m surprised in any case. Appreciate any insights.

Advertisement

Answer

firebaser here

If I check the release notes for the JavaScript SDK, there have been no changes that seem related to that in at least the last few weeks (I didn’t scroll back further).

I’m also pretty sure that createUserWithEmailAndPassword has returned a Promise <UserCredential> for at least a few years already.

I’m not sure if that type used to have a uid property, so I’m checking with some team members now.


The last relevant change I know of and can find is in version 5.0 of the SDK (release in May 2018):

Updated the return type signature for signInWithEmailAndPassword, signInWithCustomToken, signInAnonymously and createUserWithEmailAndPassword to return a promise that resolves with a UserCredential instead of a user.

So if you recently upgrade from pre-5.0 to a version 5.0 or later, you will indeed need to change your code to get the user data from response.user instead of response.

Advertisement