Created
March 30, 2020 12:37
-
-
Save equivalent/385bdc3b788b484ade0bdf9cc23ad584 to your computer and use it in GitHub Desktop.
Custom failure app for devise responding to JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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