Add the following to the top of config/initializers/devise.rb
:
class TurboFailureApp < Devise::FailureApp
def respond
if request_format == :turbo_stream
redirect
else
super
end
end
def skip_format?
%w(html turbo_stream */*).include? request_format.to_s
end
end
class TurboController < ApplicationController
class Responder < ActionController::Responder
def to_turbo_stream
controller.render(options.merge(formats: :html))
rescue ActionView::MissingTemplate => error
if get?
raise error
elsif has_errors? && default_action
render rendering_options.merge(formats: :html, status: :unprocessable_entity)
else
redirect_to navigation_location
end
end
end
self.responder = Responder
respond_to :html, :turbo_stream
end
Enable a new parent controller around line 52:
config.parent_controller = 'TurboController'
Enable navigational_formats
(around line 297):
config.navigational_formats = ['*/*', :html, :turbo_stream]
In the Warden configuration (around line 315) enable the following:
config.warden do |manager|
manager.failure_app = TurboFailureApp
end