Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete a specific user from Firebase

Is there a way I can get a specific user account from firebase and then delete it?

For instance:

// I need a means of getting a specific auth user. var user = firebase.auth().getUser(uid); // Note the getUser function is not an actual function. 

After, I want to delete that user and their additional data:

// This works user.delete().then(function() {    // User deleted.    var ref = firebase.database().ref(       "users/".concat(user.uid, "/")    );    ref.remove(); }); 

Firebase Documentation states that users can be deleted if they are currently logged in:

firebase.auth().currentUser.delete() 

My aim is to allow logged in admin user to delete other users from the system.

like image 705
b4oshany Avatar asked Aug 06 '16 04:08

b4oshany


People also ask

How do I remove a user from Firebase?

You can also delete users from the Authentication section of the Firebase console, on the Users page. Important: To delete a user, the user must have signed in recently. See Re-authenticate a user.

Which method will you call to logout a user from Firebase?

If you'd like to sign the user out of their current authentication state, call the signOut method: import auth from '@react-native-firebase/auth'; auth() . signOut() .

How do I block someone on Firebase authentication?

If you want to build a list of "blocked users" that will be able to authenticate but will have restricted access, you can store the blocked ids in a node on your firebase database like /databaseRoot/blockedUsers and then work with the security and rules .

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.


1 Answers

When using the client-side SDKs for Firebase Authentication, you can only delete the user account that is currently signed in. Anything else would be a huge security risk, as it would allow users of your app to delete each other's account.

The Admin SDKs for Firebase Authentication are designed to be used in a trusted environment, such as your development machine, a server that you control, or Cloud Functions. Because they run in a trusted environment, they can perform certain operations that the client-side SDKs can't perform, such as deleting user accounts by simply knowing their UID.

Also see:

  • delete firebase authenticated user from web application

Another common approach is to keep a whitelist/blacklist in for example the Firebase Database and authorize user based on that. See How to disable Signup in Firebase 3.x

like image 176
Frank van Puffelen Avatar answered Sep 19 '22 16:09

Frank van Puffelen