Skip to content

Instantly share code, notes, and snippets.

@equivalent
Created March 30, 2020 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save equivalent/385bdc3b788b484ade0bdf9cc23ad584 to your computer and use it in GitHub Desktop.
Save equivalent/385bdc3b788b484ade0bdf9cc23ad584 to your computer and use it in GitHub Desktop.
Custom failure app for devise responding to JS
# config/initializers/devise.rb
class CustomFailureApp < Devise::FailureApp
def http_auth_body
case request_format
when :js, 'js'
'alert(" not authorized !");'
when :json, 'json'
{ error: i18n_message }
else
i18n_message
end
end
end
Devise.setup do |config|
# ...
config.warden do |manager|
manager.failure_app = CustomFailureApp
end
# ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment