Open SrS2225a opened 1 year ago
Did you ever fix this error? I'm also getting it after following the steps outlined in the example.
+1 :/
Hello, not sure how I missed this, but I eventually decided to do it manually instead of using this middleware, as I was not able to fix the error. It was still pretty easy to add recaptcha without the help of this middleware, so I can share the details of how I accomplished this without it if interested.
FYI: in practice options
always needs a callback
parameter as per examples lower down on README.md and the supplied example. Without using the middleware, this is what I did:
const Recaptcha = require('express-recaptcha').RecaptchaV3
const options = { callback: 'cb' }
const recaptcha = new Recaptcha(process.env.RECAPTCHA_SITE_KEY, process.env.RECAPTCHA_SECRET_KEY, options)
The cb
function is in client-side JavaScript, eg:
let gRecaptchaResponse = null
function cb (token) {
gRecaptchaResponse = token
}
You might then pass gRecaptchaResponse
in an API call as the request body field 'g-recaptcha-response'
.
Server-side you can then do this call which checks 'g-recaptcha-response'
in req:
recaptcha.verify(req, function (error, data) {...
When attempting to render the recaptcha, I would get an vague error only saying that "callback is required", but as far as I can tell I am doing just that. I copied the code in the example and did not change much else. What am I missing?
Here is the full error in question: