@@ -26,26 +26,65 @@ class Engine < Rails::Engine
2626 ApplicationController . include Spree ::AuthenticationHelpers
2727 end
2828
29+ def self . redirect_back_on_unauthorized?
30+ return false unless Spree ::Config . respond_to? ( :redirect_back_on_unauthorized )
31+
32+ if Spree ::Config . redirect_back_on_unauthorized
33+ true
34+ else
35+ Spree ::Deprecation . warn <<-WARN . strip_heredoc , caller
36+ Having Spree::Config.redirect_back_on_unauthorized set
37+ to `false` is deprecated and will not be supported in Solidus 3.0.
38+ Please change this configuration to `true` and be sure that your
39+ application does not break trying to redirect back when there is
40+ an unauthorized access.
41+ WARN
42+
43+ false
44+ end
45+ end
46+
2947 def self . prepare_backend
3048 Spree ::Admin ::BaseController . unauthorized_redirect = -> do
3149 if try_spree_current_user
3250 flash [ :error ] = I18n . t ( 'spree.authorization_failure' )
33- redirect_to spree . admin_unauthorized_path
51+
52+ if Spree ::Auth ::Engine . redirect_back_on_unauthorized?
53+ redirect_back ( fallback_location : spree . admin_unauthorized_path )
54+ else
55+ redirect_to spree . admin_unauthorized_path
56+ end
3457 else
3558 store_location
36- redirect_to spree . admin_login_path
59+
60+ if Spree ::Auth ::Engine . redirect_back_on_unauthorized?
61+ redirect_back ( fallback_location : spree . admin_login_path )
62+ else
63+ redirect_to spree . admin_login_path
64+ end
3765 end
3866 end
3967 end
4068
69+
4170 def self . prepare_frontend
4271 Spree ::BaseController . unauthorized_redirect = -> do
4372 if try_spree_current_user
4473 flash [ :error ] = I18n . t ( 'spree.authorization_failure' )
45- redirect_to spree . unauthorized_path
74+
75+ if Spree ::Auth ::Engine . redirect_back_on_unauthorized?
76+ redirect_back ( fallback_location : spree . unauthorized_path )
77+ else
78+ redirect_to spree . unauthorized_path
79+ end
4680 else
4781 store_location
48- redirect_to spree . login_path
82+
83+ if Spree ::Auth ::Engine . redirect_back_on_unauthorized?
84+ redirect_back ( fallback_location : spree . login_path )
85+ else
86+ redirect_to spree . login_path
87+ end
4988 end
5089 end
5190 end
0 commit comments