2
votes

I want my users to always have access to database, and I’m using anonymous auth for that. Users can also login via facebook or google.

When user logs in, his anonymous account is converted to a social network (fb/google) account. User can then decide to log out, and when he does – he is given a new anonymous user.

If he logs in back again with his old facebook account, that new anonymous user is left in the list of users and never used again, because user is given back his social-firebase-account

How can I make sure I don’t have this plenthora of dead anonymous users in the firebase?

1
alternatively, why don't you use this permission : "auth != null"? this will also allow your users to access database - Amit Upadhyay
@AmitUpadhyay I need to save some data to the database, and when user decides to login via social networks – migrate that data to his new account to ensure it's never lost. Just putting "auth != null" will give users access but will not let them save unique data - AAverin
What version of firebase auth are you using? - Martin De Simone
@TincoDeSimone I am on 10.0.1 at the moment - AAverin

1 Answers

1
votes

Firebase Admin Node.js SDK provides an API which gives you the ability to programmatically delete users without requiring their existing password.

https://firebase.google.com/docs/reference/admin/node/admin.auth.Auth#deleteUser

You can write a Realtime Database Trigger with Cloud Functions for Firebase that deletes stale user after user status is converted from isAnonymous true to isAnonymous false.