Skip to content

Commit c008034

Browse files
JuanVqzclaude
andcommitted
Fix double render in ApplicationController auth callbacks
Both check_user_token and check_session_expiry rendered the login view without returning, causing the action to continue executing and Rails to raise AbstractController::DoubleRenderError on every unauthenticated or expired-session request. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent dd297ba commit c008034

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

app/controllers/application_controller.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@ class ApplicationController < ActionController::Base
77
private
88

99
def check_user_token
10-
unless session[:user_token]
11-
render "puzzles/login"
12-
end
10+
render "puzzles/login" and return unless session[:user_token]
1311
end
1412

1513
def check_session_expiry
1614
if session[:expires_at].present? && Time.current > session[:expires_at]
1715
reset_session
18-
render "puzzles/login"
19-
else
20-
session[:expires_at] = 1.hour.from_now
16+
render "puzzles/login" and return
2117
end
18+
19+
session[:expires_at] = 1.hour.from_now
2220
end
2321
end

test/controllers/puzzles_controller_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ class PuzzlesControllerTest < ActionDispatch::IntegrationTest
77
assert_response :success
88
end
99

10+
test "unauthenticated request renders login page" do
11+
get puzzles_path
12+
assert_response :success
13+
assert_match "login", response.body.downcase
14+
end
15+
1016
test "should show error message when editing puzzle with invalid data" do
1117
puzzle = puzzles(:one)
1218

0 commit comments

Comments
 (0)