From 05fdc93c3d341cc9853b7065eeb5126dea5467d8 Mon Sep 17 00:00:00 2001 From: Dimitris Klouvas Date: Mon, 30 Oct 2023 14:21:19 +0200 Subject: [PATCH 1/2] chore(fastify): Drop `CLERK_API_KEY` --- packages/fastify/jest.setup.js | 3 +-- .../fastify/src/__snapshots__/clerkClient.test.ts.snap | 2 +- .../fastify/src/__snapshots__/constants.test.ts.snap | 1 - packages/fastify/src/constants.test.ts | 2 -- packages/fastify/src/constants.ts | 8 -------- packages/fastify/src/withClerkMiddleware.test.ts | 9 +++------ packages/fastify/src/withClerkMiddleware.ts | 1 - 7 files changed, 5 insertions(+), 21 deletions(-) diff --git a/packages/fastify/jest.setup.js b/packages/fastify/jest.setup.js index e43456250f7..1a5dcdc343c 100644 --- a/packages/fastify/jest.setup.js +++ b/packages/fastify/jest.setup.js @@ -1,2 +1 @@ -process.env.CLERK_API_KEY = 'TEST_API_KEY'; -process.env.CLERK_SECRET_KEY = 'TEST_API_KEY'; +process.env.CLERK_SECRET_KEY = 'TEST_SECRET_KEY'; diff --git a/packages/fastify/src/__snapshots__/clerkClient.test.ts.snap b/packages/fastify/src/__snapshots__/clerkClient.test.ts.snap index aae92c52360..af94ad90c75 100644 --- a/packages/fastify/src/__snapshots__/clerkClient.test.ts.snap +++ b/packages/fastify/src/__snapshots__/clerkClient.test.ts.snap @@ -7,7 +7,7 @@ exports[`clerk initializes clerk with constants 1`] = ` "apiUrl": "https://api.clerk.com", "apiVersion": "v1", "jwtKey": "", - "secretKey": "TEST_API_KEY", + "secretKey": "TEST_SECRET_KEY", }, ], ] diff --git a/packages/fastify/src/__snapshots__/constants.test.ts.snap b/packages/fastify/src/__snapshots__/constants.test.ts.snap index 0e3330bd47e..4a12847706b 100644 --- a/packages/fastify/src/__snapshots__/constants.test.ts.snap +++ b/packages/fastify/src/__snapshots__/constants.test.ts.snap @@ -2,7 +2,6 @@ exports[`constants from environment variables 1`] = ` { - "API_KEY": "CLERK_API_KEY", "API_URL": "CLERK_API_URL", "API_VERSION": "CLERK_API_VERSION", "Cookies": { diff --git a/packages/fastify/src/constants.test.ts b/packages/fastify/src/constants.test.ts index e43db356b9e..81e9ae4e3c1 100644 --- a/packages/fastify/src/constants.test.ts +++ b/packages/fastify/src/constants.test.ts @@ -1,7 +1,6 @@ const clonedEnvVars = { CLERK_API_URL: process.env.CLERK_API_URL, CLERK_API_VERSION: process.env.CLERK_API_VERSION, - CLERK_API_KEY: process.env.CLERK_API_KEY, CLERK_SECRET_KEY: process.env.CLERK_SECRET_KEY, CLERK_FRONTEND_API: process.env.CLERK_FRONTEND_API, CLERK_PUBLISHABLE_KEY: process.env.CLERK_PUBLISHABLE_KEY, @@ -10,7 +9,6 @@ const clonedEnvVars = { process.env.CLERK_API_URL = 'CLERK_API_URL'; process.env.CLERK_API_VERSION = 'CLERK_API_VERSION'; -process.env.CLERK_API_KEY = 'CLERK_API_KEY'; process.env.CLERK_SECRET_KEY = 'CLERK_SECRET_KEY'; process.env.CLERK_FRONTEND_API = 'CLERK_FRONTEND_API'; process.env.CLERK_PUBLISHABLE_KEY = 'CLERK_PUBLISHABLE_KEY'; diff --git a/packages/fastify/src/constants.ts b/packages/fastify/src/constants.ts index 4be2eee7bec..fc7d2a58eda 100644 --- a/packages/fastify/src/constants.ts +++ b/packages/fastify/src/constants.ts @@ -3,14 +3,6 @@ import { deprecated } from '@clerk/shared/deprecated'; export const API_URL = process.env.CLERK_API_URL || 'https://api.clerk.com'; export const API_VERSION = process.env.CLERK_API_VERSION || 'v1'; -/** - * Backend API key - * @deprecated Use `CLERK_SECRET_KEY` instead. - */ -export const API_KEY = process.env.CLERK_API_KEY || ''; -if (API_KEY) { - deprecated('CLERK_API_KEY', 'Use `CLERK_SECRET_KEY` environment variable instead.'); -} export const SECRET_KEY = process.env.CLERK_SECRET_KEY || ''; /** * @deprecated Use `CLERK_PUBLISHABLE_KEY` instead. diff --git a/packages/fastify/src/withClerkMiddleware.test.ts b/packages/fastify/src/withClerkMiddleware.test.ts index 7a0bec54943..f14f92a1bbf 100644 --- a/packages/fastify/src/withClerkMiddleware.test.ts +++ b/packages/fastify/src/withClerkMiddleware.test.ts @@ -57,8 +57,7 @@ describe('withClerkMiddleware(options)', () => { expect(response.body).toEqual(JSON.stringify({ auth: 'mockedAuth' })); expect(authenticateRequestMock).toBeCalledWith( expect.objectContaining({ - secretKey: 'TEST_API_KEY', - apiKey: 'TEST_API_KEY', + secretKey: 'TEST_SECRET_KEY', request: expect.any(Request), }), ); @@ -97,8 +96,7 @@ describe('withClerkMiddleware(options)', () => { expect(response.body).toEqual(JSON.stringify({ auth: 'mockedAuth' })); expect(authenticateRequestMock).toBeCalledWith( expect.objectContaining({ - secretKey: 'TEST_API_KEY', - apiKey: 'TEST_API_KEY', + secretKey: 'TEST_SECRET_KEY', request: expect.any(Request), }), ); @@ -193,8 +191,7 @@ describe('withClerkMiddleware(options)', () => { expect(response.body).toEqual(JSON.stringify({ auth: 'mockedAuth' })); expect(authenticateRequestMock).toBeCalledWith( expect.objectContaining({ - secretKey: 'TEST_API_KEY', - apiKey: 'TEST_API_KEY', + secretKey: 'TEST_SECRET_KEY', request: expect.any(Request), }), ); diff --git a/packages/fastify/src/withClerkMiddleware.ts b/packages/fastify/src/withClerkMiddleware.ts index 7f8f718670d..42b9bb5f33c 100644 --- a/packages/fastify/src/withClerkMiddleware.ts +++ b/packages/fastify/src/withClerkMiddleware.ts @@ -14,7 +14,6 @@ export const withClerkMiddleware = (options: ClerkFastifyOptions) => { ...options, secretKey, publishableKey, - apiKey: constants.API_KEY, frontendApi: constants.FRONTEND_API, request: createIsomorphicRequest((Request, Headers) => { const requestHeaders = Object.keys(req.headers).reduce( From 385e8e279f448da57f18a50e2e5de70c13be7690 Mon Sep 17 00:00:00 2001 From: Dimitris Klouvas Date: Mon, 30 Oct 2023 17:02:13 +0200 Subject: [PATCH 2/2] chore(fastify): Drop `CLERK_FRONTEND_API` --- .changeset/lovely-mirrors-remember.md | 9 +++++++++ .../fastify/src/__snapshots__/constants.test.ts.snap | 1 - packages/fastify/src/constants.test.ts | 2 -- packages/fastify/src/constants.ts | 8 -------- packages/fastify/src/withClerkMiddleware.ts | 7 ++----- 5 files changed, 11 insertions(+), 16 deletions(-) create mode 100644 .changeset/lovely-mirrors-remember.md diff --git a/.changeset/lovely-mirrors-remember.md b/.changeset/lovely-mirrors-remember.md new file mode 100644 index 00000000000..689b626b693 --- /dev/null +++ b/.changeset/lovely-mirrors-remember.md @@ -0,0 +1,9 @@ +--- +'@clerk/fastify': major +--- + +Drop deprecations. Migration steps: +- use `CLERK_SECRET_KEY` instead of `CLERK_API_KEY` env variable +- use `secretKey` instead of `apiKey` +- use `CLERK_PUBLISHABLE_KEY` instead of `CLERK_FRONTEND_API` env variable +- use `publishableKey` instead of `frontendApi` \ No newline at end of file diff --git a/packages/fastify/src/__snapshots__/constants.test.ts.snap b/packages/fastify/src/__snapshots__/constants.test.ts.snap index 4a12847706b..a8b15646fec 100644 --- a/packages/fastify/src/__snapshots__/constants.test.ts.snap +++ b/packages/fastify/src/__snapshots__/constants.test.ts.snap @@ -8,7 +8,6 @@ exports[`constants from environment variables 1`] = ` "ClientUat": "__client_uat", "Session": "__session", }, - "FRONTEND_API": "CLERK_FRONTEND_API", "Headers": { "AuthMessage": "x-clerk-auth-message", "AuthReason": "x-clerk-auth-reason", diff --git a/packages/fastify/src/constants.test.ts b/packages/fastify/src/constants.test.ts index 81e9ae4e3c1..7803d060bc5 100644 --- a/packages/fastify/src/constants.test.ts +++ b/packages/fastify/src/constants.test.ts @@ -2,7 +2,6 @@ const clonedEnvVars = { CLERK_API_URL: process.env.CLERK_API_URL, CLERK_API_VERSION: process.env.CLERK_API_VERSION, CLERK_SECRET_KEY: process.env.CLERK_SECRET_KEY, - CLERK_FRONTEND_API: process.env.CLERK_FRONTEND_API, CLERK_PUBLISHABLE_KEY: process.env.CLERK_PUBLISHABLE_KEY, CLERK_JWT_KEY: process.env.CLERK_JWT_KEY, }; @@ -10,7 +9,6 @@ const clonedEnvVars = { process.env.CLERK_API_URL = 'CLERK_API_URL'; process.env.CLERK_API_VERSION = 'CLERK_API_VERSION'; process.env.CLERK_SECRET_KEY = 'CLERK_SECRET_KEY'; -process.env.CLERK_FRONTEND_API = 'CLERK_FRONTEND_API'; process.env.CLERK_PUBLISHABLE_KEY = 'CLERK_PUBLISHABLE_KEY'; process.env.CLERK_JWT_KEY = 'CLERK_JWT_KEY'; diff --git a/packages/fastify/src/constants.ts b/packages/fastify/src/constants.ts index fc7d2a58eda..1fab328e6e3 100644 --- a/packages/fastify/src/constants.ts +++ b/packages/fastify/src/constants.ts @@ -1,16 +1,8 @@ import { constants } from '@clerk/backend'; -import { deprecated } from '@clerk/shared/deprecated'; export const API_URL = process.env.CLERK_API_URL || 'https://api.clerk.com'; export const API_VERSION = process.env.CLERK_API_VERSION || 'v1'; export const SECRET_KEY = process.env.CLERK_SECRET_KEY || ''; -/** - * @deprecated Use `CLERK_PUBLISHABLE_KEY` instead. - */ -export const FRONTEND_API = process.env.CLERK_FRONTEND_API || ''; -if (FRONTEND_API) { - deprecated('CLERK_FRONTEND_API', 'Use `CLERK_PUBLISHABLE_KEY` environment variable instead.'); -} export const PUBLISHABLE_KEY = process.env.CLERK_PUBLISHABLE_KEY || ''; export const JWT_KEY = process.env.CLERK_JWT_KEY || ''; diff --git a/packages/fastify/src/withClerkMiddleware.ts b/packages/fastify/src/withClerkMiddleware.ts index 42b9bb5f33c..93137ff107f 100644 --- a/packages/fastify/src/withClerkMiddleware.ts +++ b/packages/fastify/src/withClerkMiddleware.ts @@ -14,7 +14,6 @@ export const withClerkMiddleware = (options: ClerkFastifyOptions) => { ...options, secretKey, publishableKey, - frontendApi: constants.FRONTEND_API, request: createIsomorphicRequest((Request, Headers) => { const requestHeaders = Object.keys(req.headers).reduce( (acc, key) => Object.assign(acc, { [key]: req?.headers[key] }), @@ -42,10 +41,8 @@ export const withClerkMiddleware = (options: ClerkFastifyOptions) => { } if (requestState.isInterstitial) { - const interstitialHtmlPage = clerkClient.localInterstitial({ - publishableKey, - frontendApi: constants.FRONTEND_API, - }); + // TODO(@dimkl): use empty string for frontendApi until type is fixed in @clerk/backend to drop it + const interstitialHtmlPage = clerkClient.localInterstitial({ publishableKey, frontendApi: '' }); return reply .code(401)