Skip to content

Commit

Permalink
fix(clerk-sdk-node): Correctly throw Missing Clerk Secret Key or API …
Browse files Browse the repository at this point in the history
…Key error
  • Loading branch information
nikosdouvlis committed Jun 15, 2023
1 parent ca1dcc3 commit f8a334b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/slow-falcons-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-sdk-node': patch
---

Correctly display "Missing Clerk keys" error instead of simply throwing during initialization
18 changes: 12 additions & 6 deletions packages/sdk-node/src/clerkClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,21 @@ let clerkClientSingleton = {} as unknown as ReturnType<typeof Clerk>;

export const clerkClient = new Proxy(clerkClientSingleton, {
get(_target, property) {
const hasBeenInitialised = !!clerkClientSingleton.authenticateRequest;
if (hasBeenInitialised) {
// @ts-expect-error
return clerkClientSingleton[property];
}

const env = { ...loadApiEnv(), ...loadClientEnv() };
if (env.secretKey) {
clerkClientSingleton = Clerk({
...env,
userAgent: '@clerk/clerk-sdk-node',
});
clerkClientSingleton = Clerk({ ...env, userAgent: '@clerk/clerk-sdk-node' });
// @ts-expect-error
return clerkClientSingleton[property];
}
// @ts-ignore
return clerkClientSingleton[property];

// @ts-expect-error
return Clerk({ ...env, userAgent: '@clerk/clerk-sdk-node' })[property];
},
set() {
return false;
Expand Down

0 comments on commit f8a334b

Please sign in to comment.