devise
devise copied to clipboard
Filter chain halted as :check_captcha rendered or redirected
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.
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.
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.
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?
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.
@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.
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!
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