diff --git a/.changeset/honest-days-fetch.md b/.changeset/honest-days-fetch.md new file mode 100644 index 00000000000..31422e2937b --- /dev/null +++ b/.changeset/honest-days-fetch.md @@ -0,0 +1,5 @@ +--- +"@clerk/testing": patch +--- + +Use `@clerk/backend` package to fetch tokens diff --git a/package-lock.json b/package-lock.json index aca046ff760..a033541e4f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -51106,6 +51106,7 @@ "version": "1.1.9", "license": "MIT", "dependencies": { + "@clerk/backend": "1.3.0", "@clerk/shared": "2.3.2", "@clerk/types": "4.7.0", "dotenv": "16.4.5" diff --git a/packages/testing/package.json b/packages/testing/package.json index 408e2c5a71d..9b437063624 100644 --- a/packages/testing/package.json +++ b/packages/testing/package.json @@ -62,6 +62,7 @@ "lint": "eslint src/" }, "dependencies": { + "@clerk/backend": "1.3.0", "@clerk/shared": "2.3.2", "@clerk/types": "4.7.0", "dotenv": "16.4.5" diff --git a/packages/testing/src/common/constants.ts b/packages/testing/src/common/constants.ts index 357fad9bf86..58ac0a27c76 100644 --- a/packages/testing/src/common/constants.ts +++ b/packages/testing/src/common/constants.ts @@ -1,3 +1 @@ export const TESTING_TOKEN_PARAM = '__clerk_testing_token'; - -export const TESTING_TOKEN_API_URL = 'https://api.clerk.com/v1/testing_tokens'; diff --git a/packages/testing/src/common/setup.ts b/packages/testing/src/common/setup.ts index 5425f2f0629..55901703c7a 100644 --- a/packages/testing/src/common/setup.ts +++ b/packages/testing/src/common/setup.ts @@ -1,7 +1,7 @@ +import { createClerkClient } from '@clerk/backend'; import { isProductionFromSecretKey, parsePublishableKey } from '@clerk/shared'; import dotenv from 'dotenv'; -import { TESTING_TOKEN_API_URL } from './constants'; import type { ClerkSetupOptions, ClerkSetupReturn } from './types'; export const fetchEnvVars = async (options?: ClerkSetupOptions): Promise => { @@ -41,29 +41,17 @@ export const fetchEnvVars = async (options?: ClerkSetupOptions): Promise { - return response.json(); - }) - .then(data => { - testingToken = data.token; - }) - .catch(reason => { - throw new Error('Failed to fetch testing token from Clerk API. Error: ' + reason); - }); + try { + const apiUrl = process.env.CLERK_API_URL; + const clerkClient = createClerkClient({ secretKey, apiUrl }); + const tokenData = await clerkClient.testingTokens.createTestingToken(); + testingToken = tokenData.token; + } catch (err) { + console.error('Failed to fetch testing token from Clerk API.'); + throw err; + } } return {