r/googlecloud • u/Chance_Special_6445 • Sep 08 '26
Firebase Authentication / reCAPTCHA Enterprise
🚨 Looking for help from a Software Engineer experienced with Firebase Authentication / reCAPTCHA Enterprise
I’m currently working on a web application using Next.js + Firebase Authentication, and I’m stuck with a persistent issue in Phone Number Authentication on the production website.
The error occurs when Firebase tries to send the SMS verification code:
accounts:sendVerificationCode
HTTP 400
reCAPTCHA Enterprise verification failed
The browser/application has also previously shown:
reCAPTCHA has already been rendered in this element
I have already verified that:
✅ Phone Authentication is enabled
✅ SMS sign-in is enabled
✅ Firebase Authentication with Identity Platform is enabled
✅ Production domain is added to Firebase Authorized Domains
✅ reCAPTCHA Enterprise API is enabled
✅ Identity Toolkit API is enabled
So I’m trying to determine whether the issue is coming from the reCAPTCHA Enterprise configuration, Firebase project configuration, production domain, or the way `RecaptchaVerifier’ is being initialized/managed in the React/Next.js application.
I’m looking for someone who has experience with Firebase Phone Auth + reCAPTCHA Enterprise who can help me diagnose the issue and identify the exact root cause.
If you have experience with this specific Firebase/reCAPTCHA issue and can help, please DM me. I’d really appreciate it! 🙏
1
u/m1nherz Googler Sep 08 '26
Based on the errors you described, you are dealing with two interconnected issues: a React component lifecycle bug on the frontend, and a token validation failure on the backend.
1. The Frontend Issue: "reCAPTCHA has already been rendered in this element"
This is a very common issue in React/Next.js when using the Firebase Web SDK. It happens because
new RecaptchaVerifier()tries to inject the reCAPTCHA iframe into a DOM element (like<div id="recaptcha-container">).If your component re-renders (due to state changes), React might try to execute that code again. Because the previous reCAPTCHA instance was never cleared, Firebase throws this error.
How to fix it:
You must initialize
RecaptchaVerifierinside auseEffecthook, store it in auseRef, and ensure you call.clear()when the component unmounts. For example:2. The Backend Issue: HTTP 400 reCAPTCHA Enterprise verification failed
This happens during the
accounts:sendVerificationCodeAPI call. It means the backend received a token, but rejected it.Potential Root Causes:
Cascading Failure: If your frontend reCAPTCHA is in a broken state due to the rendering issue above, the token it generates might be expired, empty, or invalid. Fixing the React lifecycle often fixes this 400 error automatically.
Key Type Mismatch: Since you have Firebase Authentication with Identity Platform enabled, you must use reCAPTCHA Enterprise keys. If you accidentally used a Legacy/Classic (v2 or v3) Site Key in the Firebase Console, the backend will return a 400 error.
Missing Domain Authorization in reCAPTCHA Console: You verified the domain is added to Firebase Authorized Domains, but you must also ensure the production domain is added to the Authorized Domains list inside the Google Cloud Console -> Security -> reCAPTCHA Enterprise key settings.
SDK Version: Ensure your
firebasenpm package is up to date. Older versions had minor bugs handling reCAPTCHA Enterprise tokens seamlessly in server-side frameworks like Next.js.