Skip to content

Instantly share code, notes, and snippets.

@ManickYoj
Last active January 9, 2022 03:54
Show Gist options
  • Save ManickYoj/5c4e04c224b29993d21f9d39c70eeb46 to your computer and use it in GitHub Desktop.
Save ManickYoj/5c4e04c224b29993d21f9d39c70eeb46 to your computer and use it in GitHub Desktop.
Devise Config Changes for Rails 7
# /config/initializers/devise.rb
# Turbo doesn't work with devise by default.
# Keep tabs on https://github.com/heartcombo/devise/issues/5446 for a possible fix
# Fix from https://gorails.com/episodes/devise-hotwire-turbo
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
# ...
Devise.setup do |config|
# ...
# ==> Controller configuration
# Configure the parent class to the devise controllers.
config.parent_controller = 'TurboDeviseController'
# ...
# ==> Navigation configuration
# ...
config.navigational_formats = ['*/*', :html, :turbo_stream]
# ...
# ==> Warden configuration
# ...
config.warden do |manager|
manager.failure_app = TurboFailureApp
# manager.intercept_401 = false
# manager.default_strategies(scope: :user).unshift :some_external_strategy
end
# ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment