douglasjunior / react-native-recaptcha-that-works

⚛ A reCAPTCHA bridge for React Native that works (Android and iOS)
MIT License
167 stars 33 forks source link

onExpire callback not triggering... #28

Closed misterharsh closed 2 years ago

misterharsh commented 2 years ago

https://github.com/douglasjunior/react-native-recaptcha-that-works/blob/ac70cfb9be4c18289162935af62834314b063037/src/get-template.js#L130

I think it could be because the keys are wrapped in single quotes.. other keys in the same object do not have any quote wrappings. I suspect onError is similar not working. Only onVerify gets triggered because I'm able to get the token.

Verified against the doc's that the keys are correct though: https://developers.google.com/recaptcha/docs/display

douglasjunior commented 2 years ago

How are you testing?

onExpire takes a while to run, I'm not sure how long to wait.

misterharsh commented 2 years ago

Yes, I've only gotten it to trigger maybe once and couldn't reproduce ever since. At the time, I had an alert inside the callback that ran.

However, now even with alerts or console.logs or just a simple set state to clear the token in the parent component of the Recaptcha, nothing triggers.

I was expecting that whenever the Recaptcha expires and you get that expiration text in red in the Recaptcha box, or even in the background after having gotten a token, the callback would execute. I am trying to manually close the Recaptcha, reset the token, and set my own error message in the register form on expire or error.

douglasjunior commented 2 years ago

Got it, thanks for the information.

Please, could you add a console.log(content) on line 121 to print the messages returned by webview?

https://github.com/douglasjunior/react-native-recaptcha-that-works/blob/ac70cfb9be4c18289162935af62834314b063037/src/Recaptcha.js#L120

misterharsh commented 2 years ago

console.log(content) prints: {"dispatchConfig":null,"_targetInst":null,"_dispatchListeners":null,"_dispatchInstances":null,"nativeEvent":null,"type":null,"target":null,"eventPhase":null,"bubbles":null,"cancelable":null,"defaultPrevented":null,"isTrusted":null}

and console.log(content.nativeEvent.data) right below that line prints: {"close":[]} after you click the checkbox but dont select the images, and just let it expire.

misterharsh commented 2 years ago

{"dispatchConfig":null,"_targetInst":null,"_dispatchListeners":null,"_dispatchInstances":null,"nativeEvent":null,"type":null,"target":null,"eventPhase":null,"bubbles":null,"cancelable":null,"defaultPrevented":null,"isTrusted":null}

{"load":[]}

prints when you first get the checkbox to show up.

douglasjunior commented 2 years ago

Just to clarify, the expire event should ONLY happen after you successfully get the token and wait a long time without using it.

If you open and close the captcha without solving the challenge, the expire will never happen.

But something that came to my mind now, if you get the token and close the webview, the expire will also never happen as the recaptcha component has been destroyed.

Unfortunately there is no way out, I can only document this as a known limitation.