Skip to content

Recaptcha v2 always false. Rails 7 #457

@Heahmund

Description

@Heahmund

I tried to add recaptcha on site. I use recaptcha v3 and if it false then i add v2 to the form with remote: true.
like that:
$("#captcha-v2-<%= @modal %>").html("<%= j recaptcha_tags(site_key: Rails.application.credentials.recaptcha_v2['site_key']) %>");
However v3 works fine, but v2 always false.

my controller looks like that:

  def send_callback_email
    callback = params[:callback]
    @action = params["action"]
    @modal = "callback"
    v3_secret = Rails.application.credentials.recaptcha_v3['secret_key']
    v2_secret = Rails.application.credentials.recaptcha_v2['secret_key']
    @success = verify_recaptcha(action: @action, minimum_score: 0.7, secret_key: v3_secret) ||
               verify_recaptcha(secret_key: v2_secret)
    if @success && callback[:agreement]
      ClientServiceMailer.callback_email(callback[:callback_client_name], callback[:callback_client_phone]).deliver_now
    end
    render "mailer_reply"
  end

what i tried:
i add grecaptcha.reset() But i think it is useless cause js create a new recaptcha every time after fail. So i add it just incase.
Also i tried to do form without remote true.
I checked keys and tried to do the same as in example. I do not want to use Stimulus and turbo for my site, but i added them for test.
And i tried to create another pair of keys, just incase something is wrong with mine, and i tried to use google test keys.
I tried hCaptcha too, but it leads to error for executeRecaptchaFor....
And anyway recaptcha is false. I have no idea why is that happening. Do anyone know what`s wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions