Search code examples
javascripthtmlmongodbrecaptcha

Recaptcha call back can be found when it is the only function but not when other ones are included


I am trying to make a discord bot verification page where users verify that they are not a robot. I have run into an error where Recaptcha cannot find my recaptchaCallBack function. It recognizes it when it is the only function and doesn't when other functions are included.

Here is the code:

import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.4/firebase-app.js";
            import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.6.4/firebase-analytics.js";
            import { getDatabase } from "firebase/database";
            // TODO: Add SDKs for Firebase products that you want to use
            // https://firebase.google.com/docs/web/setup#available-libraries

            // Your web app's Firebase configuration
            // For Firebase JS SDK v7.20.0 and later, measurementId is optional
            const firebaseConfig = {
                //config
            };

            // Initialize Firebase
            const app = initializeApp(firebaseConfig);
            const analytics = getAnalytics(app);
            const db = getDatabase();
            
            function recaptchaCallback() {
                set(ref(db, "verified/" + userVarFormatted), {
                    name: userVarSplitted[0],
                    discriminator: userVarSplitted[1]
                });
            }
<html>
    <head>
        <title>Jerry Bot Verication</title>
        <script src="https://www.google.com/recaptcha/api.js" async defer></script>
    </head>
    <body>
      <form action="?" method="post" data-callback="XXX" class="recaptchaDIV">
            <div class="g-recaptcha" data-callback="recaptchaCallback" data-sitekey="my site key"></div>
        </form>
      <!--My js code was here-->
    </body>
</html>

Do you know what is causing this? Thanks


Solution

  • If you're talking about just a regular web page, there's no mechanism for require("mongodb") to work. (You'd need a bundler.)

    Even if it did, a browser can't directly talk the MongoDB protocol.

    Even if it could, you'd now expose your MongoDB credentials to anyone who would visit the page, so they could read and tamper with your database however they'd like, which is likely not what you want.