Robert Clark

Joined

10 Experience
0 Lessons Completed
0 Questions Solved

Activity

Posted in How to use Devise with Hotwire & Turbo.js Discussion

I tried adding the turbo navigational format to devise and unfortunately that did not fix the problem on user destroy for me. What did end up fixing it was modifying the TurboController to match closer to what the responders gem does for other formats.

Look in lib/action_controller/responder.rb#L236-L244 of the responders gem for more context. My fix:

class DeviseTurboController < ApplicationController
  class Responder < ActionController::Responder
    def to_turbo_stream
      if @default_response
        @default_response.call(options.merge(formats: :html))
      else
        controller.render(options.merge(formats: :html))
      end
    rescue ActionView::MissingTemplate => error
      if get?
        raise error
      elsif has_errors? && default_action
        render rendering_options.merge(formats: :html, status: :unprocessable_entity)
      else
        navigation_behavior error
      end
    end
  end

  self.responder = Responder
  respond_to :html, :turbo_stream
end

The changes are centered around the default response section. This is where it was getting off the rails on user session destroy for me.