Include Turbolinks if it is installed#4678
Conversation
|
The failure app should not know about turbolinks. I know it will redirect without turbolinks in the case the authentication fails, but devise should not know anything about turbolinks and fully rendering a failure page is not a performance problem to justify this coupling. Thank you for the pull request. |
|
@rafaelfranca it's not a performance issue, no. But using Turbolinks with the wrappers for Android and iOS requires Turbolinks redirects. The Webview doesn't follow normal redirects. But I understand you don't want to include this. For anyone stumbling opon this issue, put this in your devise config: |
|
I see. We could take a different approach. Instead of adding that in the controller we could allow people to extend the devise failure app without monkey patching. Something like: ActiveSupport.run_load_hooks(:devise_failure_app)in the controller and ActiveSupport.on_load(:devise_failure_app)
include Turbolinks::Controller
endin the application initializer. But I guess this case is too common to justify we doing that part in the devise engine if |
|
I agree we can provide a lazy load hook. And it seems it shouldn't be much hard to do it. @wnm If you're willing to change this implementation to use a lazy load hook, we'd happily accept the pull request. Otherwise we can implement it in another one. Some related resources: http://api.rubyonrails.org/classes/ActiveSupport/LazyLoadHooks.html |
…port.run_load_hooks once Devise::FailureApp is loaded
|
@tegon I updated the pull request:
Hope I understood everything correctly? |
| # ==> Turbolinks configuration | ||
| # If your app is using Turbolinks, Turbolinks::Controller needs to be included to make redirection work correctly: | ||
| # | ||
| # ActiveSupport.on_load(:devise_failure_app) |
There was a problem hiding this comment.
I believe we're missing a do block here
- # ActiveSupport.on_load(:devise_failure_app)
+ # ActiveSupport.on_load(:devise_failure_app) do|
@wnm Thanks! I think that's basically it. I just think we should have a test for this. |
|
@tegon not sure if the tests are in the right place. let me know if they are not... |
|
@wnm Looks good, thanks again! |
|
This doesn't seem to be required for Rails 6 and may cause confusion. Was trying to troubleshoot and tried to toggle this config on, but it errors for me. My issue ended up being a conflict with my existing user routes. I'm not using the turbolinks gem so there's no Error: More info about rails js: https://prathamesh.tech/2019/08/26/understanding-webpacker-in-rails-6/ Just an fyi. Thanks for the PR/gems. |
Turbolinks is overwriting the redirect_to method of ActionController::Redirecting.
Devise only includes ActionController::Redirecting
So, if turbolinks is installed, it doesn't work will with devise.
This should fix it.