Sha256: 2fa1a3375dc01100a3c855d4d9b1fb298b647a02245e96d51d3f6de88aeaa766
Contents?: true
Size: 881 Bytes
Versions: 42
Compression:
Stored size: 881 Bytes
Contents
require 'jwt' require_dependency "panda_pal/application_controller" module PandaPal class ApiCallController < ApplicationController rescue_from StandardError do |err| render json: { status: 'error' }, status: 500 end rescue_from ::JWT::DecodeError do |err| render json: { status: 'error', error: "Invalid JWT" }, status: 403 end around_action do |blk| payload = ApiCall.decode_jwt(params[:token]) org_id = payload['organization_id'] if org_id PandaPal::Organization.find(org_id).switch_tenant do blk.call end else blk.call end end def call ac = ApiCall.from_jwt(params.require(:token)) result = ac.call(params.to_unsafe_h) render json: { status: 'ok', uses_remaining: ac.uses_remaining, result: result, } end end end
Version data entries
42 entries across 42 versions & 1 rubygems