Reputation: 21
I have been looking online but not yet found a way to sign out a user when there account is deleted on the firebase admin console.
Is there a way to setup maybe a cloud function or some kind of way to sign out a user when their account is deleted via the admin console.
Upvotes: 0
Views: 529
Reputation: 3842
If an account is deleted from the admin, the user's refresh token is automatically revoked so there's nothing more to do on the backend. On the frontend, the user's ID token will survive until it's natural expiration so you need a way to notify the client that their token has been revoked.
An easy way to do that is to store the user's status in the Realtime Database and then subscribe to any changes and log out the user out if that value changes.
Let's assume that your database looks like this:
{
"users": {
"userId123": {
"status": "active"
}
}
}
In your frontend code the client subscribes to /users/userId123
on page load and when the status
value changes, perform an action.
For example:
firebase.database.ref('/users/userId123/status').onWrite((change, context) => {
if (!change.after.exists()) {
callSignOut();
return null;
}
const val = change.after.val();
if (val !== 'active') {
callSignOut();
return null;
}
});
Completely untested but should get you started.
Upvotes: 1