How to update the native object of Firebase users with Angular2?

0

I have been implementing a role system while working with firebase and AngularFire2. In the end I was able to achieve it. I could do it with parallel collections in the realTime database, but I had doubts.

I would like to know if it is possible (and if so, how it would be done) to directly update a user created by the Firebase authentication system.

Let's say that I create a user programmatically:

this.af.auth.createUser({ 'email': email, 'password': password })
    .then(createdUser => {
        ...
        createdUser['role'] = foo;
        ...... // Como puedo decirle a Firebase que actualice el usuario recién creado al nuevo objeto?
    })
    .catch(err => console.log(err))

The truth is more theoretical, but I would like to know if this can be done, either with AngularFire2 or directly with the native Firebase API.

    
asked by Nano 01.12.2016 в 17:08
source

1 answer

0

Good, you can update the user with these two methods of FireBase not AngularFire2: (userdata.value has the photoURL and displayName properties)

changeUser(userData) {
 if(userData.valid) {
  console.log(userData.value);
  this.auth.currentUser.updateProfile(userData.value)
    .then((success) => {
      console.log('Success', success);
    })
    .catch((error) => {
      console.log(error);
    })
 }
}
changeEmail(emailData) {
 if(emailData.valid) {
  console.log(emailData.value);
  this.auth.currentUser.updateEmail(emailData.value.email)
    .then((_) => {
      console.log('Success');
    })
    .catch((error) => {
      console.log(error);
    })
 }
}

But if you want to assign user roles these systems do not support it directly.

    
answered by 11.02.2017 в 15:31