VividCortex / angular-recaptcha

AngularJS directive to add a reCaptcha widget to your form
http://vividcortex.github.io/angular-recaptcha/
MIT License
496 stars 257 forks source link

Error when reloading captcha #97

Closed mfrachet closed 8 years ago

mfrachet commented 8 years ago

I m actually having an error, and I don't know how to make it work. I m using version 2.2.5 and angular 1.4.2.

Actually, when I validate and loggin my application for the first time, it works great, I m well redirected.

After some navigation inside of my app, I need to disconnect the user account. So I redirect the user to the login page (where I use the recaptcha verification) and after the re-login step, I have this error :

Error: Rd(...) is null
Go@https://www.gstatic.com/recaptcha/api2/r20151214133724/recaptcha__fr.js:342:332
.getResponse@http://localhost:3000/bower_components/angular-recaptcha/release/angular-recaptcha.js:96:24
connect@http://localhost:3000/app/index.module.js:574:68
anonymous/fn@http://localhost:3000/bower_components/angular/angular.js line 13365 > Function:2:260
ngEventHandler/</callback@http://localhost:3000/bower_components/angular/angular.js:23613:17
$RootScopeProvider/this.$get</Scope.prototype.$eval@http://localhost:3000/bower_components/angular/angular.js:16052:16
$RootScopeProvider/this.$get</Scope.prototype.$apply@http://localhost:3000/bower_components/angular/angular.js:16152:20
ngEventHandler/<@http://localhost:3000/bower_components/angular/angular.js:23618:17
defaultHandlerWrapper@http://localhost:3000/bower_components/angular/angular.js:3346:3
createEventHandler/eventHandler@http://localhost:3000/bower_components/angular/angular.js:3334:9

http://localhost:3000/bower_components/angular/angular.js
Line 12520

I tried to use the reload() function when logout, but it doesn't seem to work.

What can I do ? Is this a bug ?

EDIT : It seems that my problem is on getResponse() of the recaptcha service :

console.log('Step one');
console.log(this.vcRecaptchaService.getResponse());
console.log('step two');

I can log the step one, and then it crashes

jaysongyn commented 8 years ago

I have the same issue. Any luck ?

TheSharpieOne commented 8 years ago

Did #81 not fix this for you?

TheSharpieOne commented 8 years ago

Chances are, you are loading/creating a recaptcha instance more than once. To check this, do the following: In your javascript console, when this happens, what is the value returned when you enter ___grecaptcha_cfg.count ? If the value returned is greater than 0, then you have created more than one instance, and chances are, the first one is no longer there anymore and calling it without passing a wigetId attempts to get the first one. In that case, you must call vcRecaptchaService.getResponse(widgetId) with the widgetId for the one you want to get the response from. Use the onCreate callback to get the widgetId.

Or use on-success

mfrachet commented 8 years ago

I use only one recaptcha at a time.

It seems that using the on-success attribute on HTML element made the thing work. Gonna investiguate if something was on my side or make a PR if I get something on the lib.

Thank you for the job

TheSharpieOne commented 8 years ago

You may only have one, but it probably gets rendered multiple times (even without you knowing it). For instance, if you navigate to a page which has a captcha, then navigate to a different page, then go back to the page with the captcha. It's one page with one captcha, but it was rendered multiple times. Since the page never really reloads, the recaptcha counter Google uses to identify specific instances goes up. Also, I have seen a few times where the view is rendered multiple times without navigation, causing the counter to go up. if ___grecaptcha_cfg.count is greater than 0 (0 being the first ID, meaning there is 1), then you have rendered it more than once.

jaysongyn commented 8 years ago

I solved my problem using vcRecaptchaService.getResponse(widgetId). thanks @TheSharpieOne

mtrias commented 8 years ago

I'm closing this issue as appears to be resolved. Reopen otherwise.