0

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

Jerry Lin
  • 115
  • 1
  • 9

1 Answers1

1

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.

AKX
  • 152,115
  • 15
  • 115
  • 172
  • MongoDB is working perfectly fine just recaptcha is not calling the callback function when I have code for mongoDB – Jerry Lin Jan 19 '22 at 19:33
  • It works fine if I tell it to do something simple like ```console.log("verified")``` inside the callback function. But when I tell it to connect to MongoDB and insert a document, it doesn't throw an error in the MongoDB code but instead, Recaptcha says it couldn't find my callback function. – Jerry Lin Jan 19 '22 at 19:38
  • I am also using node.js – Jerry Lin Jan 20 '22 at 16:08
  • What do you mean with "I am also using node.js"? There is no `window` (by default anyway) in Node.js you could put a recaptcha callback in. There is also no `require` in a browser. – AKX Jan 20 '22 at 16:33
  • ok so how does this have to do with ReCaptcha not finding my callback – Jerry Lin Jan 20 '22 at 17:57
  • I changed the service to firebase (which I know supports normal browser) but it still doesn't find the callback anyway. Do you know whats happening? PS I am going to edit the question – Jerry Lin Jan 21 '22 at 15:36
  • I fixed the finding callback thing but now it says ```anchor:1 Uncaught (in promise) ReferenceError``` – Jerry Lin Jan 21 '22 at 17:39
  • I’ll just ask a new wuestion – Jerry Lin Jan 21 '22 at 17:41