From de6cc4519664f18c7b0bab99b7c0ee725a67e816 Mon Sep 17 00:00:00 2001 From: Dimitris Klouvas Date: Fri, 3 Nov 2023 03:20:13 +0200 Subject: [PATCH 1/3] chore(remix): Drop `CLERK_API_KEY` and `apiKey` --- packages/remix/src/errors.ts | 4 ++-- packages/remix/src/ssr/authenticateRequest.ts | 20 ++++--------------- packages/remix/src/ssr/getAuth.ts | 2 +- packages/remix/src/ssr/types.ts | 4 ---- 4 files changed, 7 insertions(+), 23 deletions(-) diff --git a/packages/remix/src/errors.ts b/packages/remix/src/errors.ts index f4c9ecea86c..499304eef86 100644 --- a/packages/remix/src/errors.ts +++ b/packages/remix/src/errors.ts @@ -70,8 +70,8 @@ export const loader: LoaderFunction = args => rootAuthLoader(args, ({ auth }) => `); export const noSecretKeyOrApiKeyError = createErrorMessage(` -A secretKey or apiKey must be provided in order to use SSR and the exports from @clerk/remix/api.'); -If your runtime supports environment variables, you can add a CLERK_SECRET_KEY or CLERK_API_KEY variable to your config. +A secretKey must be provided in order to use SSR and the exports from @clerk/remix/api.'); +If your runtime supports environment variables, you can add a CLERK_SECRET_KEY variable to your config. Otherwise, you can pass a secretKey parameter to rootAuthLoader or getAuth. `); diff --git a/packages/remix/src/ssr/authenticateRequest.ts b/packages/remix/src/ssr/authenticateRequest.ts index 8f04a3e172b..a6a30d9ac8e 100644 --- a/packages/remix/src/ssr/authenticateRequest.ts +++ b/packages/remix/src/ssr/authenticateRequest.ts @@ -2,6 +2,7 @@ import type { RequestState } from '@clerk/backend'; import { buildRequestUrl, Clerk } from '@clerk/backend'; import { deprecated } from '@clerk/shared/deprecated'; import { handleValueOrFn } from '@clerk/shared/handleValueOrFn'; +import { isDevelopmentFromApiKey } from '@clerk/shared/keys'; import { isHttpOrHttps, isProxyUrlRelative } from '@clerk/shared/proxy'; import { isTruthy } from '@clerk/shared/underscore'; @@ -13,10 +14,6 @@ import { import { getEnvVariable } from '../utils'; import type { LoaderFunctionArgs, RootAuthLoaderOptions } from './types'; -function isDevelopmentFromApiKey(apiKey: string): boolean { - return apiKey.startsWith('test_') || apiKey.startsWith('sk_test_'); -} - /** * @internal */ @@ -31,16 +28,8 @@ export function authenticateRequest(args: LoaderFunctionArgs, opts: RootAuthLoad // 3. Then try from globalThis (Cloudflare Workers). // 4. Then from loader context (Cloudflare Pages). const secretKey = opts.secretKey || getEnvVariable('CLERK_SECRET_KEY', context) || ''; - const apiKey = opts.apiKey || getEnvVariable('CLERK_API_KEY', context) || ''; - if (apiKey) { - if (getEnvVariable('CLERK_API_KEY', context)) { - deprecated('CLERK_API_KEY', 'Use `CLERK_SECRET_KEY` instead.'); - } else { - deprecated('apiKey', 'Use `secretKey` instead.'); - } - } - if (!secretKey && !apiKey) { + if (!secretKey) { throw new Error(noSecretKeyOrApiKeyError); } @@ -93,12 +82,11 @@ export function authenticateRequest(args: LoaderFunctionArgs, opts: RootAuthLoad throw new Error(satelliteAndMissingProxyUrlAndDomain); } - if (isSatellite && !isHttpOrHttps(signInUrl) && isDevelopmentFromApiKey(secretKey || apiKey)) { + if (isSatellite && !isHttpOrHttps(signInUrl) && isDevelopmentFromApiKey(secretKey)) { throw new Error(satelliteAndMissingSignInUrl); } - return Clerk({ apiUrl, apiKey, secretKey, jwtKey, proxyUrl, isSatellite, domain }).authenticateRequest({ - apiKey, + return Clerk({ apiUrl, secretKey, jwtKey, proxyUrl, isSatellite, domain }).authenticateRequest({ audience, secretKey, jwtKey, diff --git a/packages/remix/src/ssr/getAuth.ts b/packages/remix/src/ssr/getAuth.ts index fbfa4fd8793..e14bfeb4112 100644 --- a/packages/remix/src/ssr/getAuth.ts +++ b/packages/remix/src/ssr/getAuth.ts @@ -5,7 +5,7 @@ import { authenticateRequest } from './authenticateRequest'; import type { GetAuthReturn, LoaderFunctionArgs, RootAuthLoaderOptions } from './types'; import { interstitialJsonResponse, unknownResponse } from './utils'; -type GetAuthOptions = Pick; +type GetAuthOptions = Pick; export async function getAuth(args: LoaderFunctionArgs, opts?: GetAuthOptions): GetAuthReturn { if (!args || (args && (!args.request || !args.context))) { diff --git a/packages/remix/src/ssr/types.ts b/packages/remix/src/ssr/types.ts index b8d72227408..c3bd2526039 100644 --- a/packages/remix/src/ssr/types.ts +++ b/packages/remix/src/ssr/types.ts @@ -11,10 +11,6 @@ export type RootAuthLoaderOptions = { frontendApi?: string; publishableKey?: string; jwtKey?: string; - /** - * @deprecated Use `secretKey` instead. - */ - apiKey?: string; secretKey?: string; loadUser?: boolean; loadSession?: boolean; From 0e4a98768f88592f8353ab9e116090b0d9b51040 Mon Sep 17 00:00:00 2001 From: Dimitris Klouvas Date: Fri, 3 Nov 2023 03:22:26 +0200 Subject: [PATCH 2/3] chore(remix): Drop `CLERK_FRONTEND_API` and `frontendApi` --- packages/remix/src/client/RemixClerkProvider.tsx | 2 -- packages/remix/src/client/types.ts | 1 - packages/remix/src/ssr/authenticateRequest.ts | 11 ----------- packages/remix/src/ssr/types.ts | 4 ---- packages/remix/src/ssr/utils.ts | 6 ++---- 5 files changed, 2 insertions(+), 22 deletions(-) diff --git a/packages/remix/src/client/RemixClerkProvider.tsx b/packages/remix/src/client/RemixClerkProvider.tsx index 072cb2c43b0..e01ba807e65 100644 --- a/packages/remix/src/client/RemixClerkProvider.tsx +++ b/packages/remix/src/client/RemixClerkProvider.tsx @@ -45,7 +45,6 @@ export function ClerkProvider({ children, ...rest }: RemixClerkProviderProps): J assertValidClerkState(clerkState); const { __clerk_ssr_state, - __frontendApi, __publishableKey, __proxyUrl, __domain, @@ -68,7 +67,6 @@ export function ClerkProvider({ children, ...rest }: RemixClerkProviderProps): J }, []); const mergedProps = { - frontendApi: __frontendApi as any, publishableKey: __publishableKey as any, proxyUrl: __proxyUrl as any, domain: __domain as any, diff --git a/packages/remix/src/client/types.ts b/packages/remix/src/client/types.ts index dbf330c4eeb..4fca0c9f8d2 100644 --- a/packages/remix/src/client/types.ts +++ b/packages/remix/src/client/types.ts @@ -7,7 +7,6 @@ export type ClerkState = { __internal_clerk_state: { __clerk_ssr_interstitial: string; __clerk_ssr_state: InitialState; - __frontendApi: string | undefined; __publishableKey: string | undefined; __proxyUrl: string | undefined; __domain: string | undefined; diff --git a/packages/remix/src/ssr/authenticateRequest.ts b/packages/remix/src/ssr/authenticateRequest.ts index a6a30d9ac8e..4e3fca229c0 100644 --- a/packages/remix/src/ssr/authenticateRequest.ts +++ b/packages/remix/src/ssr/authenticateRequest.ts @@ -1,6 +1,5 @@ import type { RequestState } from '@clerk/backend'; import { buildRequestUrl, Clerk } from '@clerk/backend'; -import { deprecated } from '@clerk/shared/deprecated'; import { handleValueOrFn } from '@clerk/shared/handleValueOrFn'; import { isDevelopmentFromApiKey } from '@clerk/shared/keys'; import { isHttpOrHttps, isProxyUrlRelative } from '@clerk/shared/proxy'; @@ -33,15 +32,6 @@ export function authenticateRequest(args: LoaderFunctionArgs, opts: RootAuthLoad throw new Error(noSecretKeyOrApiKeyError); } - const frontendApi = opts.frontendApi || getEnvVariable('CLERK_FRONTEND_API', context) || ''; - if (frontendApi) { - if (getEnvVariable('CLERK_FRONTEND_API', context)) { - deprecated('CLERK_FRONTEND_API', 'Use `CLERK_PUBLISHABLE_KEY` instead.'); - } else { - deprecated('frontendApi', 'Use `publishableKey` instead.'); - } - } - const publishableKey = opts.publishableKey || getEnvVariable('CLERK_PUBLISHABLE_KEY', context) || ''; const jwtKey = opts.jwtKey || getEnvVariable('CLERK_JWT_KEY', context); @@ -90,7 +80,6 @@ export function authenticateRequest(args: LoaderFunctionArgs, opts: RootAuthLoad audience, secretKey, jwtKey, - frontendApi, publishableKey, loadUser, loadSession, diff --git a/packages/remix/src/ssr/types.ts b/packages/remix/src/ssr/types.ts index c3bd2526039..ec2fd551abf 100644 --- a/packages/remix/src/ssr/types.ts +++ b/packages/remix/src/ssr/types.ts @@ -5,10 +5,6 @@ import type { DataFunctionArgs, LoaderFunction } from '@remix-run/server-runtime export type GetAuthReturn = Promise; export type RootAuthLoaderOptions = { - /** - * @deprecated Use `publishableKey` instead. - */ - frontendApi?: string; publishableKey?: string; jwtKey?: string; secretKey?: string; diff --git a/packages/remix/src/ssr/utils.ts b/packages/remix/src/ssr/utils.ts index f6fd8aa99ed..5c30cbaf225 100644 --- a/packages/remix/src/ssr/utils.ts +++ b/packages/remix/src/ssr/utils.ts @@ -86,7 +86,8 @@ export const interstitialJsonResponse = ( __loader: opts.loader, __clerk_ssr_interstitial_html: loadInterstitialFromLocal({ debugData: debugRequestState(requestState), - frontendApi: requestState.frontendApi, + // TODO(@dimkl): use empty string for frontendApi until type is fixed in @clerk/backend to drop it + frontendApi: '', publishableKey: requestState.publishableKey, // TODO: This needs to be the version of clerk/remix not clerk/react // pkgVersion: LIB_VERSION, @@ -107,7 +108,6 @@ export const injectRequestStateIntoResponse = async ( requestState: RequestState, context: AppLoadContext, ) => { - // eslint-disable-next-line @typescript-eslint/no-unused-vars const clone = response.clone(); const data = await clone.json(); @@ -151,11 +151,9 @@ export function injectRequestStateIntoDeferredData( * @internal */ export function getResponseClerkState(requestState: RequestState, context: AppLoadContext) { - // eslint-disable-next-line @typescript-eslint/no-unused-vars const { reason, message, isSignedIn, isInterstitial, ...rest } = requestState; const clerkState = wrapWithClerkState({ __clerk_ssr_state: rest.toAuth(), - __frontendApi: requestState.frontendApi, __publishableKey: requestState.publishableKey, __proxyUrl: requestState.proxyUrl, __domain: requestState.domain, From 02f88caa228633384a092f9e0195ead858eea3c3 Mon Sep 17 00:00:00 2001 From: Dimitris Klouvas Date: Fri, 3 Nov 2023 03:23:59 +0200 Subject: [PATCH 3/3] chore(repo): Add changeset --- .changeset/many-weeks-march.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .changeset/many-weeks-march.md diff --git a/.changeset/many-weeks-march.md b/.changeset/many-weeks-march.md new file mode 100644 index 00000000000..5a4e34229a1 --- /dev/null +++ b/.changeset/many-weeks-march.md @@ -0,0 +1,10 @@ +--- +'@clerk/remix': 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`