How can I disable user accounts for a firebase project from code?

I can successfully disable user accounts for a project from the console (firebase web page), but how can a user use the application to disable their user account by code whenever they want. In addition, I did not find help in the new firebase documentation.

+7
android firebase firebase-authentication
source share
2 answers

This is a bit outdated to answer the question. But only for those who are looking for the same answer, I will receive from my answer.

Using Admin SDK

Firebase Administrator (node.js) - which is not available for the mobile platform - has the ability to disable / delete a user using the Admin SDK . To disable a user, set the disable option to TRUE .

NOTE. Using the administrator SDK is not possible if your application is a browser.

enter image description here

Using Realtime Database Rules

Another option is to restrict user access (read / write) to the database by setting the Users table in the real-time database. You can add a flag field ( active ) in this table, for example:

{ "users" : { "3sFGw6zlr8VylNuvmCWd9xG1CQ43" : { "active" : true, "address" : "#123, City", "createdBy" : "2016-12-20", "mobile" : "xxxxxxx" }, "posts" : { } } 

In the above example - "3sFGw6zlr8VylNuvmCWd9xG1CQ43" is the uid generated by firebase authentication. This is the key to join this user table with the firebase user profile. The active field can easily set true or false with the usual database write operation.

And this flag field will be used to check if this account has access to database records. The following is an example:

 { "rules": { ".read": "auth !== null && root.child('users/' + auth.uid).child('active').val()==true", ".write": "auth !== null && root.child('users/' + auth.uid).child('active').val()==true", } } 

This rule will check if the user is registered and has the flag field active . Otherwise, the user will not be able to read or write to the database. On the login page, you can also check this flag field for user login and log out if the active field is false so that the user cannot log in.

EDIT: You can use the cloud features (Admin SDK). Try taking care sometimes to read about Cloud features here . Firebase Cloud Functions is a pretty useful tool for the Realtime database.

+5
source share

Reply from firebase-support@google.com :

Thanks for reaching out. Sorry, waited to get back to you. There is currently no explicit API to disable a user account. The existing workaround will be to implement a β€œdisable” flag for users, which will allow you to disable / enable your account. Please note that this flag will be stored and stored in your Firebase database. You can use this in conjunction with security rules so that after disconnecting an account, only metadata from administrators can be written to the user account.

+3
source share

All Articles