price-point-api/app/controllers/application_controller.rb

19 lines
438 B
Ruby
Raw Normal View History

2026-06-10 15:51:32 +00:00
module ApplicationController
extend ActionController::API
before_action :authenticate!
2026-06-10 15:51:32 +00:00
rescue_from Unauthorized, with: -> { render json: { error: "Unauthorized" }, status: :unauthorized }
private
def authenticate!
token = request.headers["Authorization"]&.split(" ")&.last
2026-06-10 15:51:32 +00:00
@current_user = Session.find_by(token:)&.user
raise Unauthorized unless @current_user
end
def current_user
@current_user
end
2026-05-17 11:12:43 +00:00
end