Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devise FailureApp can't include Turbo::Native::Navigation anymore #507

Open
arusa opened this issue Oct 25, 2023 · 3 comments
Open

Devise FailureApp can't include Turbo::Native::Navigation anymore #507

arusa opened this issue Oct 25, 2023 · 3 comments

Comments

@arusa
Copy link

arusa commented Oct 25, 2023

As learned from @joemasilotti, I was including Turbo::Native::Navigation in my Devise FailureApp, so I could use the method turbo_native_app? there.

Since v1.5.0 that doesn't work anymore, because Turbo::Native::Navigation uses helper_method, which is not available in Devise::FailureApp:

helper_method :turbo_native_app?

This is not a big issue, as I can easily duplicate the turbo_native_app? method.

But I wonder if this is intended, or if classes, that don't know about helpers, should still be able to include Turbo::Native::Navigation.

@seanpdoyle
Copy link
Contributor

@arusa The concern is intended to extend ActionController::Base descendants (since it's in defined in app/controllers/).

If the maintainers are interested in that kind of broader support, a PR that guarded https://github.com/hotwired/turbo-rails/blob/main/app/controllers/turbo/native/navigation.rb#L10 with a respond_to?(:helper_method) block might be enough to implement it.

@arusa
Copy link
Author

arusa commented Oct 26, 2023

Sounds like an easy solution.

If it's intended to extend ActionController::Base there could be more "features" added later that break the apps again, that include it somewhere else.

Maybe the method turbo_native_app? should live in a more generic place, where it is accessible from everywhere and Turbo::Native::Navigation could also use that.

@excid3
Copy link
Contributor

excid3 commented Nov 17, 2023

A temporary solution is to define a helper_method that does nothing:

class TurboFailureApp < Devise::FailureApp
  # Compatibility for Turbo::Native::Navigation
  class << self
    def helper_method(name)
    end
  end

  include Turbo::Native::Navigation

  # Turbo Native requests that require authentication should return 401s to trigger the login modal
  def http_auth?
    turbo_native_app? || super
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants