Files
archived-hc-harbor/app/controllers/api/admin/application_controller.rb
2025-07-01 12:14:55 -04:00

41 lines
936 B
Ruby

module Api
module Admin
class ApplicationController < ActionController::API
include ActionController::HttpAuthentication::Token::ControllerMethods
before_action :authenticate_admin_api_key!
private
def authenticate_admin_api_key!
authenticate_or_request_with_http_token do |token, options|
@admin_api_key = AdminApiKey.active.find_by(token: token)
if @admin_api_key
@current_user = @admin_api_key.user
@current_user.admin?
else
false
end
end
end
def current_user
@current_user
end
def current_admin_api_key
@admin_api_key
end
def render_unauthorized
render json: { error: "lmao no perms" }, status: :unauthorized
end
def render_forbidden
render json: { error: "lmao no perms" }, status: :forbidden
end
end
end
end