Nouf
Nouf

Reputation: 1

How to change the email and the password of the user in dart firebase

I want to change the email and the password of the user in the Firestore and authentication so the user can log in with the updated email and password

Upvotes: 0

Views: 364

Answers (1)

Renaud Tarnec
Renaud Tarnec

Reputation: 83191

I want to change the email and the password of the user

I understand that you don't want these changes to be done by the user itself, but by another user, like an admin.

In this case you cannot use the Dart firebase_auth library because the updateEmail() and updatePassword() methods must be called by the user itself.


On the other hand, with the Firebase Admin SDK you can modify an existing user's data (without authenticating as this user). To use the Admin SDK you need to do that from a privileged environment, like a server you manage or via Cloud Functions.

The following Node.js code can be used in a Cloud Function:

const uid =  .... // Specify the user's uid
getAuth()
  .updateUser(uid, {
    email: '[email protected]',
    password: 'newPassword',
  })
  .then((userRecord) => {
    // See the UserRecord reference doc for the contents of userRecord.
    console.log('Successfully updated user', userRecord.toJSON());
  })
  .catch((error) => {
    console.log('Error updating user:', error);
  });

Upvotes: 1

Related Questions