Skip to content

Commit 209efb2

Browse files
committed
Update session routes
When failing authentication, the devise route would send the user to "new_spree_user_session_path", however we want our users to be redirected to "/login." This commit deprecates the route and sends users to "/login."
1 parent 09cb89b commit 209efb2

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

config/routes.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
passwords: 'spree/user_passwords',
1111
confirmations: 'spree/user_confirmations'
1212
},
13-
skip: [:unlocks, :omniauth_callbacks],
13+
skip: [:unlocks, :omniauth_callbacks, :sessions],
1414
path_names: { sign_out: 'logout' },
1515
path_prefix: :user,
1616
router_name: :spree
@@ -19,8 +19,21 @@
1919
resources :users, only: [:edit, :update]
2020

2121
devise_scope :spree_user do
22-
get '/login', to: 'user_sessions#new', as: :login
23-
post '/login', to: 'user_sessions#create', as: :create_new_session
22+
# Legacy devise generated paths
23+
# These are deprecated but we still want to support the incoming routes,
24+
# in order to give existing stores an upgrade path.
25+
get 'user/spree_user/sign_in', to: 'user_sessions#new', as: nil
26+
post 'user/spree_user/sign_in', to: 'user_sessions#create', as: nil
27+
28+
# Custom Devise routes
29+
[:new_spree_user_session, :login].each do |helper|
30+
get '/login', to: 'user_sessions#new', as: helper
31+
end
32+
33+
[:spree_user_session, :create_new_session].each do |helper|
34+
post '/login', to: 'user_sessions#create', as: helper
35+
end
36+
2437
match '/logout', to: 'user_sessions#destroy', as: :logout, via: Devise.sign_out_via
2538
get '/signup', to: 'user_registrations#new', as: :signup
2639
post '/signup', to: 'user_registrations#create', as: :registration

spec/controllers/spree/user_passwords_controller_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
it 'redirects to the new session path' do
1111
get :edit
1212
expect(response).to redirect_to(
13-
'http://test.host/user/spree_user/sign_in'
13+
'http://test.host/login'
1414
)
1515
end
1616

0 commit comments

Comments
 (0)