angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

AppCheck Error: reCAPTCHA placeholder element must be empty

Open anisabboud opened this issue 2 years ago • 4 comments

Version info

  • Angular: 13.0.3
  • Firebase: 9.6.0 (released last week)
  • AngularFire: 7.2.0 (with rxfire 6.0.3)
  • FirebaseUI: 6.0.0 (with firebaseui-angular 6.1.0)

How to reproduce these conditions

Added and configured Firebase App Check following the documentation. In app.module.ts:

    provideAppCheck(() => initializeAppCheck(getApp(),
      { provider: new ReCaptchaV3Provider(recaptcha3SiteKey), isTokenAutoRefreshEnabled: true })),

Error in production build: (ng build --configuration=production deployed on Firebase Hosting)

Error: reCAPTCHA placeholder element must be empty which then causes: @firebase/firestore: Could not reach Cloud Firestore backend.

reCAPTCHA error in prod

Why this happens?

According to an old Stackoverflow question, it might be because "You are loading the google recaptcha library twice."

Network tab

Indeed, looking at the Network tab, recaptcha__en.js is loaded twice. reCAPTCHA loaded twice

Could the second recaptcha be loaded by something else?

I initially suspected FirebaseUI is loading the second recaptcha. However, commenting out provideAppCheck() in app.module.ts then checking the network tab shows 0 instances of recaptcha__en.js, leading to the conclusion that both were loaded through provideAppCheck().

Summary

provideAppCheck() seems to load recaptcha library twice, causing a console error and disrupting Firestore completely.

anisabboud avatar Dec 10 '21 08:12 anisabboud

This issue does not seem to follow the issue template. Make sure you provide all the required information.

google-oss-bot avatar Dec 10 '21 08:12 google-oss-bot

Facing the same issue.

Sapython avatar Apr 02 '22 13:04 Sapython

Solved it by enabling isTokenAutoRefreshEnabled: true, in app-check config.

provideAppCheck(() =>{
      console.log('app check',firebaseApp);
      return initializeAppCheck(firebaseApp, {
        provider: new ReCaptchaV3Provider(
          'abcdefghgijkmnopqrstuvwxyz-',
        ),
        isTokenAutoRefreshEnabled: true,
      })
    }),

Sapython avatar Apr 02 '22 13:04 Sapython

Update: Seems like this is related to pre-rendering, which causes the ReCaptcha library to be loaded twice.

anisabboud avatar May 22 '22 14:05 anisabboud