Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quota exceeded when updating users with Firebase Admin SDK - how can I request more?

We try to update many users in our multitenant setup, when a whole tenant needs to be enabled/disabled. With this, we sometimes run into QUOTA_EXCEEDED errors, especially for large tenants with many users. I have asked how to do this better here: Disable many users at once

As there are currently no bulk operations to update users with the Firebase Admin SDK, how can I request a quota raise?

  • I do not see an enable/disable users in the Firebase Authentication Limits

  • The error message does not indicate what has to be changed. It only says

    Exceeded quota for updating account information.

  • I do not see any limit reached on the quotas page for the project (https://console.cloud.google.com/iam-admin/quotas).

How can I raise the quota?

like image 208
Kariem Avatar asked Oct 22 '18 09:10

Kariem


1 Answers

For everybody having the same issue, here is a solution.

I contacted firebase support and got this answer

If you try to update a user’s information at once (more than 10 users or requests per second), then you'll be encountering this error message "Exceeded quota for updating account information". Please note that when we get a huge amount of requests in a short period of time, throttling is applied automatically to protect our servers. You may try sending the requests sequentially (distribute the load) instead of sending them in parallel. So basically, you'll need to process them one at a time (instead of all at once) in order to avoid the error.

So i solved this with a timeout that sends an individual record every 100ms

function listAllUsers(nextPageToken) {
        let timeout = 0;
        admin.auth().listUsers(1000, nextPageToken)
            .then(function (listUsersResult) {
                listUsersResult.users.forEach(function (userRecord) {
                    timeout = timeout + 100
                    nextUser(userRecord.uid, timeout)
                });
                if (listUsersResult.pageToken) {
                    listAllUsers(listUsersResult.pageToken);
                }
            })
            .catch(function (error) {
                console.log('Error listing users:', error);
            });
    }
    listAllUsers();

The nextUser function:

function nextUser(uid, timeout) { 
        setTimeout(() => {
            admin.auth().setCustomUserClaims(uid, { client: true }).then(() => {
            }).catch(function (error) {
                console.log('Error setting user:', error);
            });
        }, timeout);
    }
like image 75
kevinius Avatar answered Oct 02 '22 21:10

kevinius