简体   繁体   中英

Firebase Auth Reset Password (Flutter) - Get the new password

In my Flutter app, there's an admin who creates employee accounts including their passwords. They can however change their passwords later.

The admin can also remove employees

await FirebaseAuth.instance
                                .signInWithEmailAndPassword(
                                    email: employee.email,
                                    password: employee.password);
                            await FirebaseAuth.instance.currentUser!.delete();

I call the signInWithEmailAndPassword with the employee email & password & then delete the user from the admin panel

However, if the employee resets the password, the admin can no longer remove this employee as I lose track of the new password

How can I get the new password when someone calls

 await FirebaseAuth.instance
        .sendPasswordResetEmail(email: email,)
        .then((value) {});

That's pretty odd? Why would an admin need to know the passwords of every employee?

I'd suggest you set up a backend cloud function to do the removal process. On Firebase Admin SDK you can simply call the deleteUser method on the Auth object.

getAuth()
  .deleteUser(uid)
  .then(() => {
    console.log('Successfully deleted user');
  })
  .catch((error) => {
    console.log('Error deleting user:', error);
  });

Here's the detailed document: https://firebase.google.com/docs/auth/admin/manage-users#delete_a_user

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM