File tree Expand file tree Collapse file tree 4 files changed +14
-3
lines changed Expand file tree Collapse file tree 4 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ class ApplicationController < ActionController::Base
77 # Session management helpers
88 def current_user
99 @current_user ||= User . find ( session [ :user_id ] ) if session [ :user_id ]
10+ rescue ActiveRecord ::RecordNotFound
11+ # Handle case where user_id in session doesn't exist in database
12+ session [ :user_id ] = nil
13+ nil
1014 end
1115
1216 def logged_in?
@@ -35,10 +39,14 @@ def require_admin
3539
3640 def require_login_for_authenticated_routes
3741 # Skip authentication for certain routes
38- return if public_routes . include? ( request . path ) ||
39- request . path . start_with? ( '/auth/' ) ||
40- request . path . match? ( /^\/ [a-z0-9]+$/ ) # referral codes
42+ if public_routes . include? ( request . path ) ||
43+ request . path . start_with? ( '/auth/' ) ||
44+ request . path . match? ( /^\/ [a-z0-9]+$/ ) # referral codes
45+ Rails . logger . info "Skipping auth for #{ request . path } "
46+ return
47+ end
4148
49+ Rails . logger . info "Requiring auth for #{ request . path } , logged_in?: #{ logged_in? } "
4250 require_login
4351 end
4452
Original file line number Diff line number Diff line change 11class HomeController < ApplicationController
22 include ActionView ::Helpers ::DateHelper
3+ skip_before_action :require_login_for_authenticated_routes
34 def index
45 @recent_visits = Visit . includes ( :user )
56 . recent
Original file line number Diff line number Diff line change 11class ReferralsController < ApplicationController
22 include ApplicationHelper
3+ skip_before_action :require_login_for_authenticated_routes
34 def show
45 @referral_code = params [ :referral_code ]
56 @referrer = User . find_by ( referral_code : @referral_code )
Original file line number Diff line number Diff line change 11class SessionsController < ApplicationController
2+ skip_before_action :require_login_for_authenticated_routes
23 def github
34 # This action is no longer needed - we'll use a form that POSTs directly to /auth/github
45 redirect_to '/auth/github' , allow_other_host : true
You can’t perform that action at this time.
0 commit comments