Skip to content

Commit 231e3de

Browse files
authored
Redirect to root after sign in (#615)
To still allow editing password, a profile link is added in `application.html.erb`.
1 parent daae089 commit 231e3de

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

app/controllers/sessions_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class SessionsController < ApplicationController
44
def new
55
authorize :session
6-
redirect_to edit_user_path if current_user.present?
6+
redirect_to root_path if current_user.present?
77
end
88

99
def create
@@ -12,7 +12,7 @@ def create
1212
if @user&.authenticate(params[:session][:password])
1313
# TODO: Allow option to have long-lived sessions
1414
session[:user_id] = @user.id
15-
redirect_to edit_user_path
15+
redirect_to root_path
1616
else
1717
render 'new', status: :unprocessable_entity
1818
end

app/views/layouts/application.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<%- if current_user.present? %>
1818
<%= link_to t('.home'), root_path(search: session[:entry_search]) %>
1919
<%= link_to t('.subscriptions'), subscriptions_path %>
20+
<%= link_to t('.profile'), edit_user_path %>
2021
<%= link_to t('.sign_out'), destroy_session_path, data: { turbo_method: :delete } %>
2122
<%- if current_user.admin? %>
2223
<%= link_to t('.good_job'), good_job_path, data: { turbo: false } %>

config/locales/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ en:
5555
subscriptions: All subscriptions
5656
good_job: Good job dashboard
5757
home: Home
58+
profile: Profile
5859
sign_out: Sign out
5960
sessions:
6061
new:

test/controllers/sessions_controller_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ class SessionsControllerTest < ActionDispatch::IntegrationTest
1818

1919
get new_session_url
2020

21-
assert_redirected_to user_url
21+
assert_redirected_to root_url
2222
end
2323

2424
test 'should log in user' do
2525
post session_url, params: { session: { email: 'example@example.org', password: 'password1234' } }
2626

27-
assert_redirected_to user_url
27+
assert_redirected_to root_url
2828
assert_equal @user.id, session[:user_id]
2929
end
3030

0 commit comments

Comments
 (0)