diff --git a/.changeset/rude-jobs-yawn.md b/.changeset/rude-jobs-yawn.md new file mode 100644 index 00000000000..9138d536935 --- /dev/null +++ b/.changeset/rude-jobs-yawn.md @@ -0,0 +1,8 @@ +--- +'@clerk/nextjs': patch +'@clerk/remix': patch +'gatsby-plugin-clerk': patch +'@clerk/shared': patch +--- + +Improve the default value for CLERK_API_URL by utilizing the publishable key to differentiate between local, staging and prod environments. diff --git a/packages/gatsby-plugin-clerk/src/constants.ts b/packages/gatsby-plugin-clerk/src/constants.ts index 4e8e2abf1f9..74c0639a68c 100644 --- a/packages/gatsby-plugin-clerk/src/constants.ts +++ b/packages/gatsby-plugin-clerk/src/constants.ts @@ -1,6 +1,8 @@ +import { apiUrlFromPublishableKey } from '@clerk/shared'; import { deprecated } from '@clerk/shared/deprecated'; -export const API_URL = process.env.CLERK_API_URL || 'https://api.clerk.com'; +export const PUBLISHABLE_KEY = process.env.GATSBY_CLERK_PUBLISHABLE_KEY || ''; +export const API_URL = process.env.CLERK_API_URL || apiUrlFromPublishableKey(PUBLISHABLE_KEY); export const API_VERSION = process.env.CLERK_API_VERSION || 'v1'; /** * @deprecated Use `CLERK_SECRET_KEY` instead. @@ -17,7 +19,6 @@ export const FRONTEND_API = process.env.GATSBY_CLERK_FRONTEND_API || ''; if (FRONTEND_API) { deprecated('FRONTEND_API', 'Use `PUBLISHABLE_KEY` environment variable instead.'); } -export const PUBLISHABLE_KEY = process.env.GATSBY_CLERK_PUBLISHABLE_KEY || ''; export const CLERK_JS = process.env.GATSBY_CLERK_JS; export const PROXY_URL = process.env.GATSBY_CLERK_PROXY_URL; diff --git a/packages/remix/src/ssr/authenticateRequest.ts b/packages/remix/src/ssr/authenticateRequest.ts index 713e7c23437..1aa656eec21 100644 --- a/packages/remix/src/ssr/authenticateRequest.ts +++ b/packages/remix/src/ssr/authenticateRequest.ts @@ -1,6 +1,12 @@ import type { RequestState } from '@clerk/backend'; import { buildRequestUrl, Clerk } from '@clerk/backend'; -import { deprecated, handleValueOrFn, isHttpOrHttps, isProxyUrlRelative } from '@clerk/shared'; +import { + apiUrlFromPublishableKey, + deprecated, + handleValueOrFn, + isHttpOrHttps, + isProxyUrlRelative, +} from '@clerk/shared'; import { noSecretKeyOrApiKeyError, @@ -54,7 +60,7 @@ export function authenticateRequest(args: LoaderFunctionArgs, opts: RootAuthLoad const jwtKey = opts.jwtKey || getEnvVariable('CLERK_JWT_KEY', context); - const apiUrl = getEnvVariable('CLERK_API_URL', context); + const apiUrl = getEnvVariable('CLERK_API_URL', context) || apiUrlFromPublishableKey(publishableKey); const domain = handleValueOrFn(opts.domain, new URL(request.url)) || getEnvVariable('CLERK_DOMAIN', context) || '';