-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
verifyCallback not called #228
Comments
It was behaving slightly differently in my case (Gatsby website), in that the callback was only getting called if landing on the form from another page, not if accessing the form page directly 😕 Possibly some bug hiding somewhere in the Anyways, after copy-pasting the code down and starting to dissect it to pinpoint the issue, I ended up using this stripped-down version, which works a charm for me: import React, {Component} from 'react';
import PropTypes from 'prop-types';
// Wait for the recaptcha object to become available
// The promise will resolve as soon as needed, keep resolving with the
// cached object.
const waitForRecaptcha = new Promise(resolve=> {
let interval = setInterval(()=> {
if (typeof window !== 'undefined' && typeof window.grecaptcha !== 'undefined') {
clearInterval(interval);
resolve(window.grecaptcha);
}
}, 1000);
});
export default class Recaptcha extends Component {
constructor(props) {
super(props);
this.state = {widget: null};
this._containerRef = null;
}
componentDidMount() {
this._renderGrecaptcha();
}
_renderGrecaptcha() {
const {sitekey, theme, type, size, tabindex, hl, badge,
verifyCallback, expiredCallback, onloadCallback} = this.props;
waitForRecaptcha.then(grecaptcha=> {
const widget = grecaptcha.render(this._containerRef, {
sitekey, theme, type, size, tabindex, hl, badge,
callback: verifyCallback,
'expired-callback': expiredCallback,
});
this.setState({widget});
});
if (onloadCallback) {
onloadCallback();
}
}
render() {
return <div ref={el=> this._containerRef = el} />;
}
}
Recaptcha.propTypes = {
onloadCallback: PropTypes.func,
verifyCallback: PropTypes.func,
expiredCallback: PropTypes.func,
sitekey: PropTypes.string.isRequired,
theme: PropTypes.string,
type: PropTypes.string,
size: PropTypes.string,
tabindex: PropTypes.string,
hl: PropTypes.string,
badge: PropTypes.string,
};
Recaptcha.defaultProps = {
onloadCallback: undefined,
verifyCallback: undefined,
expiredCallback: undefined,
theme: 'light',
type: 'image',
size: 'normal',
tabindex: '0',
hl: 'en',
badge: 'bottomright',
}; |
Having same problem. Needed this for redux-form. |
+1 |
1 similar comment
+1 |
@rshk Thanks for sharing your version, seems to be working for me! |
+1 |
2 similar comments
+1 |
+1 |
The problem is that this library is not following the newest Recaptcha API. For example: I have some spare time tomorrow and I'll try to make this library compatible with the current Recaptcha API so it would work in all the cases described in the docs. |
Btw, can I ask pretty please people finding this issue in the future to just click the "thumbs up" on the issue description, instead of commenting with just a |
Hey guys! It took me a little bit more time to make it happen, but it's here! My approach has some improvements comparing to this lib and most important - it works! 😄 🚀 What's awesome - you can have everything in your React component (not outside in some global variables). Verify callback also works like a charm! Library: https://github.com/sarneeh/reaptcha Hope it helps! 😄 🎉 If you'll encounter any problems, just file an issue - I'm available right now and will fix anything pretty fast. 💃 |
Same mistake for me |
On many occasions,
verifyCallback
is not called. I don't think it's a deterministic process, but it always happens after the recaptcha asks the user to filter some images.The text was updated successfully, but these errors were encountered: