price-point-api/app/controllers/application_controller.rb
Mohammad Kanaan 13992e1dbe
Some checks failed
CI / scan_ruby (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / test (push) Has been cancelled
feat: implement user authentication and session management
2026-06-14 14:12:37 +03:00

26 lines
531 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_session = Session.find_by(token: token)
raise Unauthorized unless @current_session
@current_user = @current_session.user
end
def current_user
@current_user
end
def current_session
@current_session
end
end