(RESOLVED) Ref child and set firebase

I’m trying add data in Authentication module and Database module through this code

createUser(user: any, path: string): Promise<any> {
    return firebase.auth().createUserWithEmailAndPassword(user.email, user.password)
    .then( newUser => {
      firebase.database()
      .ref(`/users/${path}/`)
      .child(newUser.uid)
      .set(user);
    });
  }

in other projects this work fine, but in this I don’t know, this way its sava data (email and password) only in Authentication Module but not in Database Module, whats happening, someone ?

did you fix this?

having the same problem with this:

signupUser(email: string, password: string): Promise {
return firebase
.auth()
.createUserWithEmailAndPassword(email, password)
.then( newUser => {
firebase
.database()
.ref(’/userProfile’)
.child(newUser.uid)
.set({ email: email });
});
}

newUser.uid is not working for me anymore. It used to work a few months ago I’m sure

yea my friend, to me, it was a problem of version firebase, so I remove firebase and install again firebase but in version “firebase”: “^4.8.0”, and “angularfire2”: “^5.0.0-rc.4”, then resolve to me

Hey Rafael,

I don’t think that should be the solution, instead, it’s a good idea to read libraries release notes to see what changes between different versions.

Firebase 5.0.0 refactored how the createUserWithEmailAndPassword() works, it now does not return a firebase.User but a firebase.UserCredential object, and that credential object has the user inside.

For example, this:

createUser(user: any, path: string): Promise<any> {
  return firebase.auth()
  .createUserWithEmailAndPassword(user.email, user.password)
  .then( newUser => {
    firebase.database()
    .ref(`/users/${path}/`)
    .child(newUser.uid)
    .set(user);
  });
}

Will be refactored as this:

createUser(user: any, path: string): Promise<any> {
  return firebase.auth()
  .createUserWithEmailAndPassword(user.email, user.password)
  .then( newUserCredential => {
    firebase.database()
    .ref(`/users/${path}/`)
    .child(newUserCredential.user.uid)
    .set(user);
  });
}

That way you can keep updating your Firebase library and making sure things keep working.

If you’re also using #AngularFire2 I wrote a guide on how to update to latest RC using the rxjs-compat library here: https://javebratt.com/upgrade-firebase-5/

Nice friend, I don’t know why but I think that I already had tryied to install the latest libraries without success, its not had worked, curious …I’ll go read your guide about it, thanks