vol1ura/Sat_9am_5km

View on GitHub
app/controllers/api/parkzhrun/application_controller.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
# frozen_string_literal: true

module API
  module Parkzhrun
    class ApplicationController < ActionController::API
      respond_to :json
      before_action :authorize_request

      private

      def authorize_request
        return if request.headers['Authorization'] == Rails.application.credentials.parkzhrun_api_key

        render json: { error: 'Token invalid' }, status: :unauthorized
      end
    end
  end
end