Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(remix): Drop deprecations #2022

Merged
merged 3 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/many-weeks-march.md
Original file line number Diff line number Diff line change
@@ -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`
2 changes: 0 additions & 2 deletions packages/remix/src/client/RemixClerkProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export function ClerkProvider({ children, ...rest }: RemixClerkProviderProps): J
assertValidClerkState(clerkState);
const {
__clerk_ssr_state,
__frontendApi,
__publishableKey,
__proxyUrl,
__domain,
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion packages/remix/src/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions packages/remix/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
`);

Expand Down
31 changes: 4 additions & 27 deletions packages/remix/src/ssr/authenticateRequest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,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';

Expand All @@ -13,10 +13,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
*/
Expand All @@ -31,28 +27,11 @@ 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);
}

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);
Expand Down Expand Up @@ -93,16 +72,14 @@ 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,
frontendApi,
publishableKey,
loadUser,
loadSession,
Expand Down
2 changes: 1 addition & 1 deletion packages/remix/src/ssr/getAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { authenticateRequest } from './authenticateRequest';
import type { GetAuthReturn, LoaderFunctionArgs, RootAuthLoaderOptions } from './types';
import { interstitialJsonResponse, unknownResponse } from './utils';

type GetAuthOptions = Pick<RootAuthLoaderOptions, 'apiKey' | 'secretKey'>;
type GetAuthOptions = Pick<RootAuthLoaderOptions, 'secretKey'>;

export async function getAuth(args: LoaderFunctionArgs, opts?: GetAuthOptions): GetAuthReturn {
if (!args || (args && (!args.request || !args.context))) {
Expand Down
8 changes: 0 additions & 8 deletions packages/remix/src/ssr/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,8 @@ import type { DataFunctionArgs, LoaderFunction } from '@remix-run/server-runtime
export type GetAuthReturn = Promise<AuthObject>;

export type RootAuthLoaderOptions = {
/**
* @deprecated Use `publishableKey` instead.
*/
frontendApi?: string;
publishableKey?: string;
jwtKey?: string;
/**
* @deprecated Use `secretKey` instead.
*/
apiKey?: string;
secretKey?: string;
loadUser?: boolean;
loadSession?: boolean;
Expand Down
6 changes: 2 additions & 4 deletions packages/remix/src/ssr/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();

Expand Down Expand Up @@ -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,
Expand Down
Loading