mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
eba2527b8e
As has been seen in a previous pull request, some applications require routes to be loaded before the code is eagerly loaded, which implies that all Rails applications using Devise need to have routes reloaded twice: https://github.com/plataformatec/devise/pull/3241 This can incur a very significant slowdown for large apps that have a lot of routes or a lot of controllers, so reloading should be optional.
49 lines
1.4 KiB
Ruby
49 lines
1.4 KiB
Ruby
require 'devise/rails/routes'
|
|
require 'devise/rails/warden_compat'
|
|
|
|
module Devise
|
|
class Engine < ::Rails::Engine
|
|
config.devise = Devise
|
|
|
|
# Initialize Warden and copy its configurations.
|
|
config.app_middleware.use Warden::Manager do |config|
|
|
Devise.warden_config = config
|
|
end
|
|
|
|
# Force routes to be loaded if we are doing any eager load.
|
|
config.before_eager_load do |app|
|
|
app.reload_routes! if Devise.reload_routes
|
|
end
|
|
|
|
initializer "devise.url_helpers" do
|
|
Devise.include_helpers(Devise::Controllers)
|
|
end
|
|
|
|
initializer "devise.omniauth", after: :load_config_initializers, before: :build_middleware_stack do |app|
|
|
Devise.omniauth_configs.each do |provider, config|
|
|
app.middleware.use config.strategy_class, *config.args do |strategy|
|
|
config.strategy = strategy
|
|
end
|
|
end
|
|
|
|
if Devise.omniauth_configs.any?
|
|
Devise.include_helpers(Devise::OmniAuth)
|
|
end
|
|
end
|
|
|
|
initializer "devise.secret_key" do |app|
|
|
if app.respond_to?(:secrets)
|
|
Devise.secret_key ||= app.secrets.secret_key_base
|
|
elsif app.config.respond_to?(:secret_key_base)
|
|
Devise.secret_key ||= app.config.secret_key_base
|
|
end
|
|
|
|
Devise.token_generator ||=
|
|
if secret_key = Devise.secret_key
|
|
Devise::TokenGenerator.new(
|
|
ActiveSupport::CachingKeyGenerator.new(ActiveSupport::KeyGenerator.new(secret_key))
|
|
)
|
|
end
|
|
end
|
|
end
|
|
end
|