From 79f443c83dd1c549289c1572af544db63957fefc Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Sat, 21 Dec 2024 23:31:40 +0100 Subject: [PATCH] Use Solidus 4.4 Redirect extension points if available This makes the `prepare_{frontend,backend}` methods which instantiate the base controller and the admin base controller, requiring all of ActionController::Base, unnecessary to call for newer Solidus versions. Depends on https://github.com/solidusio/solidus/pull/6051 --- lib/spree/auth/engine.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/spree/auth/engine.rb b/lib/spree/auth/engine.rb index 0c2aa82..2573e30 100644 --- a/lib/spree/auth/engine.rb +++ b/lib/spree/auth/engine.rb @@ -21,10 +21,19 @@ class Engine < Rails::Engine Spree::Auth::Config = Spree::AuthConfiguration.new end - config.to_prepare do - Spree::Auth::Engine.prepare_backend if SolidusSupport.backend_available? - Spree::Auth::Engine.prepare_frontend if SolidusSupport.frontend_available? + if Spree::Config.respond_to?(:unauthorized_redirect_handler_class) + Spree::Config.unauthorized_redirect_handler_class = "Spree::Auth::UnauthorizedCustomerAccessHandler" + if SolidusSupport.backend_available? + Spree::Backend::Config.unauthorized_redirect_handler_class = "Spree::Auth::UnauthorizedAdminAccessHandler" + end + else + config.to_prepare do + Spree::Auth::Engine.prepare_backend if SolidusSupport.backend_available? + Spree::Auth::Engine.prepare_frontend if SolidusSupport.frontend_available? + end + end + config.to_prepare do ApplicationController.include Spree::AuthenticationHelpers end