devise icon indicating copy to clipboard operation
devise copied to clipboard

Filter chain halted as :check_captcha rendered or redirected

Open sbryans opened this issue 3 years ago • 7 comments

The /users/sign_in page works swimmingly with captcha integration. The /users/sign_up page, however, does not. I've followed the guide @ https://github.com/heartcombo/devise/wiki/How-To:-Use-Recaptcha-with-Devise to the letter.

Environment

  • Ruby [2.6.3]
  • Rails [6.0.3.4]
  • Devise [4.7.3]

Current behavior

Filter chain halted as :check_captcha rendered or redirected. Captcha never passes.

Expected behavior

Captcha should pass when entered correctly.

sbryans avatar Mar 21 '21 17:03 sbryans

I seem to have the same issue. Rails 6.0.0 and same devise version. Ruby 2.5.1 Also followed the guide and also in sign_up.

schepens83 avatar Apr 24 '21 17:04 schepens83

Okay. I think actually the guide is wrong. In return if !verify_recaptcha(action: 'signup') It seems to skip the rest of the method if recaptcha fails instead of succeeds. Removing the ! fixed the problem for me.

schepens83 avatar Apr 25 '21 07:04 schepens83

That seems to make sense @schepens83. I have never used recaptcha with Devise in that way but I can try to build up a test app and review the wiki to see what's misguided there.

@sbryans you mention sign in works but sign up doesn't, have you noticed any difference between the two? The wiki example has the same "issue" above on all of them it seems, but maybe you coded sign in vs up differently?

carlosantoniodasilva avatar Apr 26 '21 22:04 carlosantoniodasilva

In my sessions_controller.rb override for Devise.

prepend_before_action :check_captcha, only: [:create] ... def check_captcha unless verify_recaptcha self.resource = resource_class.new sign_in_params respond_with_navigational(resource) { render :new } end end ...

The registrations_controller.rb is similar, yet only the sessions controller seems to work. I'm sure it's a simple configuration issue on my part.

sbryans avatar May 05 '21 12:05 sbryans

@schepens83 Yeah, I needed to do this for "sign in" form after following the guide also. It seems that maybe the logic was reversed in the recaptcha gem? Either way, deleting the exclamation mark worked for me.

DoctorZine avatar Sep 23 '21 21:09 DoctorZine

Just confirming, the docs are backwards! :-)

return if verify_recaptcha

Is the correct statement!

Otherwise you get in a loop back to the login page, and not completing the capture will log you in OK!

firecall avatar Nov 22 '21 08:11 firecall

I have the same problem
prepend_before_action :check_captcha, only: [:new, :create] ... def check_captcha unless verify_recaptcha self.resource = resource_class.new sign_up_params respond_with_navigational(resource) do flash.discard(:recaptcha_error) redirect_to new_user_registration_path end end end ... 07:43:00 web.1 | Filter chain halted as :check_captcha rendered or redirected

mices avatar Aug 26 '23 12:08 mices