-
Notifications
You must be signed in to change notification settings - Fork 31
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
return token promise by recaptcha.execute #9
base: master
Are you sure you want to change the base?
Conversation
I like the idea. However, the callback will be executed twice when reCAPTCHA is resolved successfully, wouldn't it? |
to avoid this I just pass the 'noop function' as an <Recaptcha
ref={_ => this.recaptcha = _}
sitekey='***'
onResolved={() => null}
/> it is not very nice but doesn't break old API |
Please do. I do like the idea. I will follow up after your update. Thanks. |
TL;DRThis promise is not a good idea due to Google reCAPTCHA's lack of an error callback, which would provide the only proper mechanism for promise rejection. Without it, we risk forever-pending promises. An alternate, non-prop means of assigning If As an alternative, you can dip your toes in callback hell and add an class GoogleRecaptcha extends Component {
...
componentDidMount() {
...
this.onResolved = action => window[this.callbackName] = action;
...
}
...
} And in your validation & submission flow, something like this: const submitArgs = [foo, bar, baz];
if (googleRecaptchaRef) {
googleRecaptchaRef.onResolved(() => {
submit(...submitArgs, googleRecaptcha);
});
googleRecaptcha.execute();
}
else {
submit(...submitArgs);
}
function submit(foo, bar, baz, googleRecaptcha) {
...
const googleRecaptchaResponse = googleRecaptcha && googleRecaptcha.getResponse();
...
} |
@Palisand, you make a valid point. Your comment is visionary. I do hesitate regarding the possible pending promise. I tend not to make a merge with a heuristic. Sorry for the late response. |
885a65a
to
9c7f8cb
Compare
after this changes you can use recaptcha.execute this way:
so you dont't need
onResolved
andgetResponse
methods