firebase-admin-node: auth/internal-error calling `generateEmailVerificationLink` or `generatePasswordResetLink`
Describe your environment
- Operating System version: Firebase Functions Environment
- Firebase SDK version: 7.0.0
- Library version: 7.0.0
- Firebase Product: auth
Describe the problem
I’m facing internal-error when calling the auth functions to generate Email verification link or password verification link. It throws the error randomly, some time it is successful, but its not consistent. There is no rate limit mentioned for the functions generateEmailVerificationLink and generatePasswordResetLink. Other operations of auth like getUser and setCustomClaims works fine in the same execution where the above mention two functions are failing.
The complete error response is:
{"error":{"code":400,"message":"TOO_MANY_ATTEMPTS_TRY_LATER","errors":[{"message":"TOO_MANY_ATTEMPTS_TRY_LATER","domain":"global","reason":"invalid"}]}}
Steps to reproduce:
The below code captures the flow of auth operation executions in my application.
Relevant Code:
let promises = [];
let auth = admin.auth();
let hrstart = process.hrtime();
async function testAuth(i) {
let email = `email+test${i}@gmail.com`;
let user;
try {
user = await auth.createUser({email, password: 'password1234567890'});
} catch (e) {
console.log('error creating user', email, e);
// return Promise.reject(e);
}
try {
await auth.setCustomUserClaims(user.uid, {abc: `testwqa`});
} catch (e) {
console.log('error writing user claims', email, e);
// return Promise.reject(e);
}
try {
user = await auth.getUser(user.uid);
} catch (e) {
console.log('error reading user ', email, user.uid, e);
// return Promise.reject(e);
}
let link, plink;
try {
link = await auth.generateEmailVerificationLink(user.email, {url: `https://${projectId}.firebaseapp.com/redeem-reward`});
} catch (e) {
console.log('error generating email link for ', user.uid, e);
// return Promise.reject(e);
}
try {
plink = await auth.generatePasswordResetLink(user.email, {url: `https://${projectId}.firebaseapp.com/redeem-reward`});
} catch (e) {
console.log('error generating password link for ', user.uid, e);
// return Promise.reject(e);
}
return {user, link, plink};
}
for (let i = 0; i < 3; i++) {
promises.push(testAuth(i));
}
Promise.all(promises)
.then(value => {
let hrend = process.hrtime(hrstart);
console.log(hrend);
console.log(value)
});
Error log:

About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 9
- Comments: 27 (8 by maintainers)
One thing to ensure if you’re running into this is that you’re not using the same email address across multiple attempts. I found through experimentation that it will only allow a link to be generated once per minute per email address… Which seems a perfectly reasonable thing to do to avoid spamming someone, but should still be mentioned in the limits documentation. I do not see this issue if I switch addresses between attempts.
After spending 10+ hours trying to resolve this issue of getting rate limited on the 2nd query, I’ve had to completely remove Firebase Email Verification from my codebase. This just shows how limited platforms like Firebase are for production grade environments.
I experience the same error, but even on the first invocation.
Code: TL;DR operating on firestore and on RTDB, then generating a link on user creation
Error shown in function logs:
Tried with multiple projects, same result.
I wasn’t able to verify the QPS limit per IP address. But I can lookup the email link generation limit per day for each operation and document it.
Ok, so you will end up getting throttled at some point as email link generation is not meant to be run in batches as you appear to be doing. You will need to apply some throttling on your end. If you can figure out the number of requests you are able to send before getting throttled, that could help determine whether throttling is excessive or not for this operation.
You are better off opening a support ticket for this. The support team will help connect you directly to the backend engineers in charge of this. The GitHub repo is not the right place for these issues. I can only help diagnose the issue and play middleman but can’t look into the usage logs for your project or make changes to fix this.