module Authentication extend ActiveSupport::Concern included do before_action :authenticate end private def authenticate if authenticated_user = User.find_by(id: cookies.encrypted[:user_id]) Current.user = authenticated_user else redirect_to new_session_url end end end
module SetCurrentRequestDetails extend ActiveSupport::Concern included do before_action do Current.request_id = request.uuid Current.user_agent = request.user_agent Current.ip_address = request.ip end end end class ApplicationController < ActionController::Base include Authentication include SetCurrentRequestDetails end
config/credentials.yml.encͷத # aws: # access_key_id: 123 # secret_access_key: 345 # Used as the base secret for all MessageVerifiers in Rails, including the one protecting cookies. secret_key_base: b4e08f4b6314eaab0d52c5cafcf51f6c38f0160d82c05bae2007d d9fb08f3efec68fca32a0ec473a653a84259b461165443b17c15e 5666b3924c3afc78730e9c