janko / rodauth-rails

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

Fix rails api-only check #29

Closed dmitryzuev closed 3 years ago

dmitryzuev commented 3 years ago

Hey,

I noticed that for fresh Rails 6.1.2 app in api-only mode error from https://github.com/janko/rodauth-rails/issues/13 is still present.

NoMethodError (undefined method `flash' for #<ActionDispatch::Request:0x00007fe26ad93600>):

This is because ActionDispatch::Flash is existing constant in the app, but it doesn't included in Request:

$ rails c
Loading development environment (Rails 6.1.2)
[1] pry(main)> defined? ActionDispatch::Flash
=> "constant"
[2] pry(main)> ActionDispatch::Request.ancestors.include?(ActionDispatch::Flash::RequestMethods)
=> false

This PR changes rails api-only check so it'll rely on Rails configuration instead of defined constants.

Hope this help someone like me!

janko commented 3 years ago

Thanks for the patch. I guess supporting API-only mode is harder than I thought. I wanted to support API-only apps that may be manually including ActionDispatch::Flash, but that's hard to detect. Better to safely support the most common use cases instead 👍🏻