price-point-api/app/controllers/application_controller.rb
Mohammad Kanaan ed626b5066 WIP 2
2026-06-10 19:16:28 +03:00

21 lines
433 B
Ruby

class ApplicationController < ActionController::API
include Renderable
before_action :authenticate!
rescue_from Unauthorized do
render_error("Unauthorized", :unauthorized)
end
private
def authenticate!
token = request.headers["Authorization"]&.split(" ")&.last
@current_user = Session.find_by(token:)&.user
raise Unauthorized unless @current_user
end
def current_user
@current_user
end
end