gambosite/app/controllers/application_controller.rb

24 lines
630 B
Ruby
Raw Normal View History

2025-01-24 10:22:13 -08:00
class ApplicationController < ActionController::Base
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
allow_browser versions: :modern
2025-01-27 10:36:57 -08:00
def authenticate
unless authenticate_api_key?
unauthorized_response
end
end
def authenticate_api_key?
api_key = request.headers["X-API-KEY"]
if api_key.present? && ApiKey.exists?(key: api_key)
@apikey = ApiKey.find_by(key: api_key)
return true
end
false
end
def unauthorized_response
render json: { error: "API key is missing or empty" }, status: :unauthorized
end
2025-01-24 10:22:13 -08:00
end