Skip to content

Commit

Permalink
Only store user location if the user has to log in. Was causing us to…
Browse files Browse the repository at this point in the history
… require log in for controllers that should not, like resetting passwords
  • Loading branch information
DanielJackson-Oslo committed Feb 17, 2024
1 parent df4ae33 commit 059d2b6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
17 changes: 0 additions & 17 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,6 @@
class ApplicationController < ActionController::Base
before_action :set_paper_trail_whodunnit
before_action :configure_permitted_parameters, if: :devise_controller?
before_action :store_user_location!, if: :storable_location?

private

def storable_location?
if devise_controller? && action_name == "edit" && current_user.nil?
redirect_to new_user_session_path
return true
end

request.get? && is_navigational_format? && !devise_controller? && !request.xhr?
end

def store_user_location!
# :user is the scope we are authenticating
store_location_for(:user, request.fullpath)
end

protected

Expand Down
17 changes: 17 additions & 0 deletions app/controllers/base_controllers/authenticate_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@
module BaseControllers
class AuthenticateController < ApplicationController
before_action :authenticate_user!
before_action :store_user_location!, if: :storable_location?

private

def storable_location?
if devise_controller? && action_name == "edit" && current_user.nil?
redirect_to new_user_session_path
return true
end

request.get? && is_navigational_format? && !devise_controller? && !request.xhr?
end

def store_user_location!
# :user is the scope we are authenticating
store_location_for(:user, request.fullpath)
end

protected

Expand Down

0 comments on commit 059d2b6

Please sign in to comment.