Skip to content

Instantly share code, notes, and snippets.

@maxloncar
Last active November 17, 2022 12:31
Show Gist options
  • Save maxloncar/723414e1a1cf4a21a891c815e6f1407e to your computer and use it in GitHub Desktop.
Save maxloncar/723414e1a1cf4a21a891c815e6f1407e to your computer and use it in GitHub Desktop.
Initializer if OmniAuth decides not to cooperate with your project when dealing with raised exceptions after unsuccessful login attempts
# config/initializers/fix_omniauth.rb
begin
require "omniauth"
require "omniauth/version"
rescue LoadError => e
warn "Could not load 'omniauth'. Please ensure you have the omniauth gem >= 1.0.0 installed and listed in your Gemfile."
raise
end
# Clean up the default path_prefix. It will be automatically set by Devise.
OmniAuth.config.path_prefix = nil
OmniAuth.config.on_failure = Proc.new do |env|
env['devise.mapping'] = Devise.mappings[:user]
controller_name = ActiveSupport::Inflector.camelize(env['devise.mapping'].controllers[:omniauth_callbacks])
controller_klass = ActiveSupport::Inflector.constantize("#{controller_name}Controller")
controller_klass.action(:failure).call(env)
end
module Devise
module OmniAuth
autoload :Config, "devise/omniauth/config"
autoload :UrlHelpers, "devise/omniauth/url_helpers"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment