docbrown/app/controllers/concerns/session_current_user.rb
Jacob Herrington 5afb4d9a24
[15-Minute Fix] Refactor code smells (#13347)
* Remove duplicate method calls

* DRY up duplicated code

* Address code smells in concerns

* Update based on PR feedback
2021-04-21 14:52:32 -05:00

12 lines
358 B
Ruby

# Used throughout the app to access a user id through the session
module SessionCurrentUser
extend ActiveSupport::Concern
# Extracts the current user ID from the session
def session_current_user_id
return unless (key = session["warden.user.user.key"])
# the value is in the format [[1], "..."] where 1 is the ID
key.first.first
end
end