ToolJet/app/controllers/application_controller.rb

21 lines
554 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2021-03-31 13:38:49 +00:00
class ApplicationController < ActionController::API
2021-04-29 06:41:23 +00:00
include Pundit
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
2021-03-31 16:18:42 +00:00
2021-04-29 06:41:23 +00:00
before_action :authenticate_request
attr_reader :current_user
2021-04-29 06:41:23 +00:00
private
def authenticate_request
@current_user = AuthorizeApiRequest.call(request.headers).result
render json: { error: "Not Authorized" }, status: :unauthorized unless @current_user
end
2021-04-29 06:41:23 +00:00
def user_not_authorized
render json: { error: "Access denied" }, status: :forbidden
end
2021-03-31 13:38:49 +00:00
end