Skip to content

Commit

Permalink
fix: Properly set API key in Faraday 2
Browse files Browse the repository at this point in the history
This fixes a regression introduced with #37, which caused the Clerk API
key to not be properly set when requesting Clerk's Backend API, when
Faraday v2 was used.

Fixes #37 (comment)
  • Loading branch information
agis committed Oct 31, 2023
1 parent 579e665 commit fb75b99
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
clerk-sdk-ruby (2.10.0)
clerk-sdk-ruby (2.11.0)
concurrent-ruby (~> 1.1)
faraday (>= 1.4.1, < 3.0)
jwt (~> 2.5)
Expand All @@ -19,7 +19,7 @@ GEM
faraday-net_http (3.0.2)
jwt (2.7.1)
minitest (5.20.0)
rake (13.0.6)
rake (13.1.0)
ruby2_keywords (0.0.5)
timecop (0.9.8)

Expand Down
9 changes: 6 additions & 3 deletions lib/clerk/rack_middleware_v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,15 @@ def unknown(interstitial: false, **opts)
end

def development_or_staging?
Clerk.configuration.api_key.start_with?("test_") ||
Clerk.configuration.api_key.start_with?("sk_test_")
Clerk.configuration.api_key &&
(Clerk.configuration.api_key.start_with?("test_") ||
Clerk.configuration.api_key.start_with?("sk_test_"))
end

def production?
!development_or_staging?
Clerk.configuration.api_key &&
(Clerk.configuration.api_key.start_with?("live_") ||
Clerk.configuration.api_key.start_with?("sk_live_"))
end

def cross_origin_request?(req)
Expand Down
8 changes: 4 additions & 4 deletions lib/clerk/sdk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ def initialize(api_key: nil, base_url: nil, logger: nil, ssl_verify: true,
URI(base_url)
end

api_key ||= if Faraday::VERSION.to_i < 2
Clerk.configuration.api_key
elsif Clerk.configuration.api_key.nil?
-> { raise ArgumentError, "Clerk secret key is not set" }
api_key ||= Clerk.configuration.api_key

if Faraday::VERSION.to_i >= 2 && api_key.nil?
api_key = -> { raise ArgumentError, "Clerk secret key is not set" }
end

logger = logger || Clerk.configuration.logger
Expand Down

0 comments on commit fb75b99

Please sign in to comment.