Skip to content

Commit

Permalink
fix(clerk-sdk-node): Fix forgotten Clerk instead of createClerkClient
Browse files Browse the repository at this point in the history
This error was silent due to a existing ts-expect-error that
was added in the past for a different reason. To allow type
checking for the import, we splitted it to 2 different lines
and added the ts-expect-error only to the part that we wanted to.
  • Loading branch information
dimkl committed Dec 15, 2023
1 parent 381fc58 commit 85da7a4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/weak-bears-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-sdk-node': minor
---

Fix error thrown for undefined `Clerk` in case of using default clerkClient from `@clerk/clerk-sdk-node` without secretKey caused by replaced import.
7 changes: 4 additions & 3 deletions packages/sdk-node/src/clerkClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function createClerkClient(options: ClerkOptions): ClerkClient {
let clerkClientSingleton = {} as unknown as ReturnType<typeof createClerkClient>;

export const clerkClient = new Proxy(clerkClientSingleton, {
get(_target, property) {
get(_target, property: string) {
const hasBeenInitialised = !!clerkClientSingleton.authenticateRequest;
if (hasBeenInitialised) {
// @ts-expect-error - Element implicitly has an 'any' type because expression of type 'string | symbol' can't be used to index type 'ExtendedClerk'.
Expand All @@ -40,13 +40,14 @@ export const clerkClient = new Proxy(clerkClientSingleton, {

const env = { ...loadApiEnv(), ...loadClientEnv() };
if (env.secretKey) {
clerkClientSingleton = createClerkClient({ ...env, userAgent: '@clerk/clerk-sdk-node' });
clerkClientSingleton = createClerkClient({ ...env, userAgent: PACKAGE_NAME });
// @ts-expect-error - Element implicitly has an 'any' type because expression of type 'string | symbol' can't be used to index type 'ExtendedClerk'.
return clerkClientSingleton[property];
}

const c = createClerkClient({ ...env, userAgent: PACKAGE_NAME });
// @ts-expect-error - Element implicitly has an 'any' type because expression of type 'string | symbol' can't be used to index type 'ExtendedClerk'.
return Clerk({ ...env, userAgent: '@clerk/clerk-sdk-node' })[property];
return c[property];
},
set() {
return false;
Expand Down

0 comments on commit 85da7a4

Please sign in to comment.