Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I reset a user's password using the Firebase Admin SDK for Node?

The docs from Firebase suggest that the API offers the same features as the console:

It is not always convenient to have to visit the Firebase console in order to manage your Firebase users. The admin user management API provides programmatic access to those same users. It even allows you to do things the Firebase console cannot, such as retrieving a user's full data and changing a user's password, email address or phone number.

But the reference docs don't list a function to reset a user's password. Am I missing something?

like image 573
Oliver Lloyd Avatar asked Sep 25 '17 12:09

Oliver Lloyd


People also ask

What is the use of Firebase Admin SDK?

The Admin SDK is a set of server libraries that lets you interact with Firebase from privileged environments to perform actions like: Read and write Realtime Database data with full admin privileges.

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/… .

How do I reset my Firebase password?

To send a password reset email to user, on the Users page, hover over the user and click ... > Reset password. The user will receive an email with instructions on how to reset their password.

What is the firebase admin SDK and how does it work?

As the developer or the administrator of an app built on Firebase, you may need to perform various user management tasks. These include: Querying user profile information to populate dashboards or compile reports The Firebase Admin SDK provides a powerful API for performing these kinds of user management tasks from privileged environments.

How do I reset a user's password in Firebase?

In order to reset the password for a particular user, you will need access to the given project in Firebase. Step 4 - Hover over the user record, and select the context menu on the right The user will receive an email with a link to reset their password.

How to access Google Cloud Platform resources in Firebase?

Access Google Cloud Platform resources like Cloud Storage buckets and Cloud Firestore databases associated with your Firebase projects. Create your own simplified admin console to do things like look up user data or change a user’s email address for authentication. To use Admin SDK, you need to add firebase-admin npm package to your project first:

Is there a way to reset a user's password via admin SDK?

If, on the other hand, you mean reset as in 'send a password reset email', then no, there doesn't seem to be a simple way of doing so via the Admin SDK. Show activity on this post. Yes, you can. To generate a password reset link, you provide the existing user's email. Then you can use any email service you like to send the actual email.


2 Answers

EDIT: This answer is now out of date, see Andrea's answer below for how to send a password reset link through the Firebase SDK.

It depends on which definition of 'reset' you're using.

If you mean reset as in 'change', then yes - the updateUser function allows you to provide a new password. See the following example from the docs:

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);
  });

If, on the other hand, you mean reset as in 'send a password reset email', then no, there doesn't seem to be a simple way of doing so via the Admin SDK.

like image 118
Joe Clay Avatar answered Sep 21 '22 15:09

Joe Clay


Yes, you can. To generate a password reset link, you provide the existing user's email. Then you can use any email service you like to send the actual email. Link to documentation.

// Admin SDK API to generate the password reset link.
const userEmail = '[email protected]';
admin.auth().generatePasswordResetLink(userEmail, actionCodeSettings)
  .then((link) => {
    // Construct password reset email template, embed the link and send
    // using custom SMTP server.
    return sendCustomPasswordResetEmail(email, displayName, link);
  })
.catch((error) => {
  // Some error occurred.
});
like image 27
Andrea Avatar answered Sep 19 '22 15:09

Andrea