janko / rodauth-rails

Rails integration for Rodauth authentication framework
https://github.com/jeremyevans/rodauth
MIT License
584 stars 40 forks source link

undefined method `allow_forgery_protection=' #22

Closed adilsoncarvalho closed 3 years ago

adilsoncarvalho commented 3 years ago

Hello mate,

I am trying your standard configuration on my rails-api app, and I am getting this error below.

My code is running on ruby@2.7.2, rails@6.1.0 and rodauth-rails@0.7.0.

NoMethodError (undefined method `allow_forgery_protection=' for #<RodauthController:0x000000000066d0>):

app/lib/rodauth_app.rb:146:in `block in <class:RodauthApp>'

It seems that there is something here that is triggering the problem

class RodauthApp < Rodauth::Rails::App
  configure json: :only do
    # List of authentication features that are loaded.
    enable :create_account, :verify_account, :verify_account_grace_period,
      :login, :logout, :jwt,
      :reset_password, :change_password, :change_password_notify,
      :change_login, :verify_login_change,
      :close_account

  # lots of stuff

  route do |r|
    # the line below is the 146
    r.rodauth # route rodauth requests
  end

  # more stuff
end
janko commented 3 years ago

Thanks for the report. I'm assuming the RodauthController is a descendant of ActionController::API, correct? It seems I haven't handled this scenario properly, I will push a fix shortly with better tests.

adilsoncarvalho commented 3 years ago

Yeap, I reached exactly that controller: ActionController::API.

adilsoncarvalho commented 3 years ago

Thanks mate for this quick fix. I had the chance to test today, and now I can reach rodauth with no problems.

image