Skip to content

Commit eb66e00

Browse files
committed
chore(*): Rename isDevelopmentFromApiKey to isDevelopmentFromSecretKey
1 parent 0155212 commit eb66e00

File tree

9 files changed

+24
-24
lines changed

9 files changed

+24
-24
lines changed

packages/backend/src/tokens/interstitialRule.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { checkCrossOrigin } from '../util/request';
2-
import { isDevelopmentFromApiKey, isProductionFromApiKey } from '../util/shared';
2+
import { isDevelopmentFromSecretKey, isProductionFromApiKey } from '../util/shared';
33
import type { AuthStatusOptionsType, RequestState } from './authStatus';
44
import { AuthErrorReason, interstitial, signedIn, signedOut } from './authStatus';
55
import { verifyToken } from './verify';
@@ -45,7 +45,7 @@ const isBrowser = (userAgent: string | undefined) => VALID_USER_AGENTS.test(user
4545
// automatically treated as signed out. This exception is needed for development, because the any // missing uat throws an interstitial in development.
4646
export const nonBrowserRequestInDevRule: InterstitialRule = options => {
4747
const { secretKey, userAgent } = options;
48-
if (isDevelopmentFromApiKey(secretKey || '') && !isBrowser(userAgent)) {
48+
if (isDevelopmentFromSecretKey(secretKey || '') && !isBrowser(userAgent)) {
4949
return signedOut(options, AuthErrorReason.HeaderMissingNonBrowser);
5050
}
5151
return undefined;
@@ -70,7 +70,7 @@ export const crossOriginRequestWithoutHeader: InterstitialRule = options => {
7070

7171
export const isPrimaryInDevAndRedirectsToSatellite: InterstitialRule = options => {
7272
const { secretKey = '', isSatellite, searchParams } = options;
73-
const isDev = isDevelopmentFromApiKey(secretKey);
73+
const isDev = isDevelopmentFromSecretKey(secretKey);
7474

7575
if (isDev && !isSatellite && shouldRedirectToSatelliteUrl(searchParams)) {
7676
return interstitial(options, AuthErrorReason.PrimaryRespondsToSyncing);
@@ -80,7 +80,7 @@ export const isPrimaryInDevAndRedirectsToSatellite: InterstitialRule = options =
8080

8181
export const potentialFirstLoadInDevWhenUATMissing: InterstitialRule = options => {
8282
const { secretKey = '', clientUat } = options;
83-
const res = isDevelopmentFromApiKey(secretKey);
83+
const res = isDevelopmentFromSecretKey(secretKey);
8484
if (res && !clientUat) {
8585
return interstitial(options, AuthErrorReason.CookieUATMissing);
8686
}
@@ -96,7 +96,7 @@ export const potentialRequestAfterSignInOrOutFromClerkHostedUiInDev: Interstitia
9696
const crossOriginReferrer =
9797
referrer && checkCrossOrigin({ originURL: new URL(referrer), host, forwardedHost, forwardedProto });
9898

99-
if (isDevelopmentFromApiKey(secretKey) && crossOriginReferrer) {
99+
if (isDevelopmentFromSecretKey(secretKey) && crossOriginReferrer) {
100100
return interstitial(options, AuthErrorReason.CrossOriginReferrer);
101101
}
102102
return undefined;

packages/backend/src/tokens/request.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { constants } from '../constants';
22
import { assertValidSecretKey } from '../util/assertValidSecretKey';
33
import { buildRequest, stripAuthorizationHeader } from '../util/IsomorphicRequest';
4-
import { isDevelopmentFromApiKey } from '../util/shared';
4+
import { isDevelopmentFromSecretKey } from '../util/shared';
55
import type { AuthStatusOptionsType, RequestState } from './authStatus';
66
import { AuthErrorReason, interstitial, signedOut, unknownState } from './authStatus';
77
import type { TokenCarrier } from './errors';
@@ -32,7 +32,7 @@ export type OptionalVerifyTokenOptions = Partial<
3232
export type AuthenticateRequestOptions = AuthStatusOptionsType & OptionalVerifyTokenOptions & { request: Request };
3333

3434
function assertSignInUrlExists(signInUrl: string | undefined, key: string): asserts signInUrl is string {
35-
if (!signInUrl && isDevelopmentFromApiKey(key)) {
35+
if (!signInUrl && isDevelopmentFromSecretKey(key)) {
3636
throw new Error(`Missing signInUrl. Pass a signInUrl for dev instances if an app is satellite`);
3737
}
3838
}

packages/backend/src/util/shared.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export { addClerkPrefix, getScriptUrl, getClerkJsMajorVersionOrTag } from '@clerk/shared/url';
22
export { callWithRetry } from '@clerk/shared/callWithRetry';
3-
export { isDevelopmentFromApiKey, isProductionFromApiKey, parsePublishableKey } from '@clerk/shared/keys';
3+
export { isDevelopmentFromSecretKey, isProductionFromApiKey, parsePublishableKey } from '@clerk/shared/keys';
44
export { deprecated, deprecatedProperty } from '@clerk/shared/deprecated';
55

66
import { buildErrorThrower } from '@clerk/shared/error';

packages/nextjs/src/server/authMiddleware.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { AuthObject, RequestState } from '@clerk/backend';
22
import { buildRequestUrl, constants, TokenVerificationErrorReason } from '@clerk/backend';
33
import { DEV_BROWSER_JWT_MARKER, setDevBrowserJWTInURL } from '@clerk/shared/devBrowser';
4-
import { isDevelopmentFromApiKey } from '@clerk/shared/keys';
4+
import { isDevelopmentFromSecretKey } from '@clerk/shared/keys';
55
import type { Autocomplete } from '@clerk/types';
66
import type Link from 'next/link';
77
import type { NextFetchEvent, NextMiddleware, NextRequest } from 'next/server';
@@ -162,7 +162,7 @@ const authMiddleware: AuthMiddleware = (...args: unknown[]) => {
162162

163163
if (isIgnoredRoute(req)) {
164164
logger.debug({ isIgnoredRoute: true });
165-
if (isDevelopmentFromApiKey(options.secretKey || SECRET_KEY) && !params.ignoredRoutes) {
165+
if (isDevelopmentFromSecretKey(options.secretKey || SECRET_KEY) && !params.ignoredRoutes) {
166166
console.warn(
167167
receivedRequestForIgnoredRoute(req.experimental_clerkUrl.href, JSON.stringify(DEFAULT_CONFIG_MATCHER)),
168168
);
@@ -296,7 +296,7 @@ const appendDevBrowserOnCrossOrigin = (req: WithClerkUrl<NextRequest>, res: Resp
296296
if (
297297
shouldAppendDevBrowser &&
298298
!!location &&
299-
isDevelopmentFromApiKey(opts.secretKey || SECRET_KEY) &&
299+
isDevelopmentFromSecretKey(opts.secretKey || SECRET_KEY) &&
300300
isCrossOrigin(req.experimental_clerkUrl, location)
301301
) {
302302
const dbJwt = req.cookies.get(DEV_BROWSER_JWT_MARKER)?.value || '';
@@ -345,7 +345,7 @@ const isRequestMethodIndicatingApiRoute = (req: NextRequest): boolean => {
345345
* In development, attempt to detect clock skew based on the requestState. This check should run when requestState.isInterstitial is true. If detected, we throw an error.
346346
*/
347347
const assertClockSkew = (requestState: RequestState, opts: AuthMiddlewareParams): void => {
348-
if (!isDevelopmentFromApiKey(opts.secretKey || SECRET_KEY)) {
348+
if (!isDevelopmentFromSecretKey(opts.secretKey || SECRET_KEY)) {
349349
return;
350350
}
351351

@@ -363,7 +363,7 @@ const assertInfiniteRedirectionLoop = (
363363
opts: AuthMiddlewareParams,
364364
requestState: RequestState,
365365
): NextResponse => {
366-
if (!isDevelopmentFromApiKey(opts.secretKey || SECRET_KEY)) {
366+
if (!isDevelopmentFromSecretKey(opts.secretKey || SECRET_KEY)) {
367367
return res;
368368
}
369369

@@ -403,7 +403,7 @@ const withNormalizedClerkUrl = (req: NextRequest): WithClerkUrl<NextRequest> =>
403403
};
404404

405405
const informAboutProtectedRoute = (path: string, params: AuthMiddlewareParams, isApiRoute: boolean) => {
406-
if (params.debug || isDevelopmentFromApiKey(params.secretKey || SECRET_KEY)) {
406+
if (params.debug || isDevelopmentFromSecretKey(params.secretKey || SECRET_KEY)) {
407407
console.warn(
408408
informAboutProtectedRouteInfo(
409409
path,

packages/nextjs/src/server/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { RequestState } from '@clerk/backend';
22
import { buildRequestUrl, constants } from '@clerk/backend';
33
import { handleValueOrFn } from '@clerk/shared/handleValueOrFn';
4-
import { isDevelopmentFromApiKey } from '@clerk/shared/keys';
4+
import { isDevelopmentFromSecretKey } from '@clerk/shared/keys';
55
import { isHttpOrHttps } from '@clerk/shared/proxy';
66
import type { NextRequest } from 'next/server';
77
import { NextResponse } from 'next/server';
@@ -239,7 +239,7 @@ export const handleMultiDomainAndProxy = (req: NextRequest, opts: WithAuthOption
239239
throw new Error(missingDomainAndProxy);
240240
}
241241

242-
if (isSatellite && !isHttpOrHttps(signInUrl) && isDevelopmentFromApiKey(SECRET_KEY)) {
242+
if (isSatellite && !isHttpOrHttps(signInUrl) && isDevelopmentFromSecretKey(SECRET_KEY)) {
243243
throw new Error(missingSignInUrlInDev);
244244
}
245245

packages/remix/src/ssr/authenticateRequest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { RequestState } from '@clerk/backend';
22
import { buildRequestUrl, Clerk } from '@clerk/backend';
33
import { apiUrlFromPublishableKey } from '@clerk/shared/apiUrlFromPublishableKey';
44
import { handleValueOrFn } from '@clerk/shared/handleValueOrFn';
5-
import { isDevelopmentFromApiKey } from '@clerk/shared/keys';
5+
import { isDevelopmentFromSecretKey } from '@clerk/shared/keys';
66
import { isHttpOrHttps, isProxyUrlRelative } from '@clerk/shared/proxy';
77
import { isTruthy } from '@clerk/shared/underscore';
88

@@ -69,7 +69,7 @@ export function authenticateRequest(args: LoaderFunctionArgs, opts: RootAuthLoad
6969
throw new Error(satelliteAndMissingProxyUrlAndDomain);
7070
}
7171

72-
if (isSatellite && !isHttpOrHttps(signInUrl) && isDevelopmentFromApiKey(secretKey)) {
72+
if (isSatellite && !isHttpOrHttps(signInUrl) && isDevelopmentFromSecretKey(secretKey)) {
7373
throw new Error(satelliteAndMissingSignInUrl);
7474
}
7575

packages/sdk-node/src/authenticateRequest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { RequestState } from '@clerk/backend';
22
import { buildRequestUrl, constants, createIsomorphicRequest } from '@clerk/backend';
33
import { handleValueOrFn } from '@clerk/shared/handleValueOrFn';
4-
import { isDevelopmentFromApiKey } from '@clerk/shared/keys';
4+
import { isDevelopmentFromSecretKey } from '@clerk/shared/keys';
55
import { isHttpOrHttps, isProxyUrlRelative, isValidProxyUrl } from '@clerk/shared/proxy';
66
import type { ServerResponse } from 'http';
77

@@ -73,7 +73,7 @@ export const authenticateRequest = (opts: AuthenticateRequestParams) => {
7373
throw new Error(satelliteAndMissingProxyUrlAndDomain);
7474
}
7575

76-
if (isSatellite && !isHttpOrHttps(signInUrl) && isDevelopmentFromApiKey(secretKey || '')) {
76+
if (isSatellite && !isHttpOrHttps(signInUrl) && isDevelopmentFromSecretKey(secretKey || '')) {
7777
throw new Error(satelliteAndMissingSignInUrl);
7878
}
7979

packages/shared/src/__tests__/keys.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
buildPublishableKey,
33
createDevOrStagingUrlCache,
4-
isDevelopmentFromApiKey,
4+
isDevelopmentFromSecretKey,
55
isProductionFromApiKey,
66
isPublishableKey,
77
parsePublishableKey,
@@ -83,7 +83,7 @@ describe('isDevOrStagingUrl(url)', () => {
8383
});
8484
});
8585

86-
describe('isDevelopmentFromApiKey(key)', () => {
86+
describe('isDevelopmentFromSecretKey(key)', () => {
8787
const cases: Array<[string, boolean]> = [
8888
['sk_live_Y2xlcmsuY2xlcmsuZGV2JA==', false],
8989
['sk_test_Y2xlcmsuY2xlcmsuZGV2JA==', true],
@@ -92,7 +92,7 @@ describe('isDevelopmentFromApiKey(key)', () => {
9292
];
9393

9494
test.each(cases)('given %p as a publishable key string, returns %p', (publishableKeyStr, expected) => {
95-
const result = isDevelopmentFromApiKey(publishableKeyStr);
95+
const result = isDevelopmentFromSecretKey(publishableKeyStr);
9696
expect(result).toEqual(expected);
9797
});
9898
});

packages/shared/src/keys.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export function createDevOrStagingUrlCache() {
7070
};
7171
}
7272

73-
export function isDevelopmentFromApiKey(apiKey: string): boolean {
73+
export function isDevelopmentFromSecretKey(apiKey: string): boolean {
7474
return apiKey.startsWith('test_') || apiKey.startsWith('sk_test_');
7575
}
7676

0 commit comments

Comments
 (0)