Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update an user as admin in Firebase

I've a web application and I want, as the Admin user, to be able to update the information like displayName and photoURL of other users with Firebase authentication.

Typically if we want to update the user information we use firebase.User.updateProfile() but that just works for the current user, and, as I've mentioned before, I'm logged in with an admin account and I want to update other users' profiles.

My question is: Is there a function to which you can pass the uid and the information of an user to be updated?

Thanks.

like image 478
Lucas David Ferrero Avatar asked Oct 19 '17 19:10

Lucas David Ferrero


People also ask

Can you change user UID Firebase?

uid cannot be changed. You can create your own custom uid for users. You will need a users table which uses your custom uid rather than the one created by Firebase.

What is the difference between Firebase and Firebase admin?

The admin SDK runs your code with administrative permissions. This means it bypasses the security rules of your Firebase Database. It also has functionality to manage users and mint custom tokens and can be used to send FCM messages.

How can I get user details from Firebase?

If the user login with a custom "email/password" you don't know anything else about that user (apart from the unique user id). If a user login with Facebook, or with Google sign in, you can get other information like the profile picture url. It is explained here: firebase.google.com/docs/auth/android/… .


1 Answers

You can do so with the Firebase Admin SDK:

admin.auth().updateUser(uid, {
  email: "[email protected]",
  phoneNumber: "+11234567890",
  emailVerified: true,
  password: "newPassword",
  displayName: "Jane Doe",
  photoURL: "http://www.example.com/12345678/photo.png",
  disabled: true
})
  .then(function(userRecord) {
    // See the UserRecord reference doc for the contents of `userRecord`.
    console.log("Successfully updated user", userRecord.toJSON());
  })
    .catch(function(error) {
      console.log("Error updating user:", error);
    });
like image 72
bojeil Avatar answered Sep 30 '22 23:09

bojeil