2026-06-10 15:51:32 +00:00
|
|
|
module ApplicationController
|
|
|
|
|
extend ActionController::API
|
2026-05-30 21:27:35 +00:00
|
|
|
before_action :authenticate!
|
|
|
|
|
|
2026-06-10 15:51:32 +00:00
|
|
|
rescue_from Unauthorized, with: -> { render json: { error: "Unauthorized" }, status: :unauthorized }
|
|
|
|
|
|
2026-05-30 21:27:35 +00:00
|
|
|
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
|
2026-05-30 21:27:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def current_user
|
|
|
|
|
@current_user
|
|
|
|
|
end
|
2026-05-17 11:12:43 +00:00
|
|
|
end
|