Skip to content

Commit

Permalink
feat(remix,gatsby-plugin-clerk): Improve CLERK_API_URL default value
Browse files Browse the repository at this point in the history
  • Loading branch information
desiprisg committed Oct 30, 2023
1 parent ee15771 commit 1a2021c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .changeset/rude-jobs-yawn.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 3 additions & 2 deletions packages/gatsby-plugin-clerk/src/constants.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
10 changes: 8 additions & 2 deletions packages/remix/src/ssr/authenticateRequest.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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) || '';

Expand Down

0 comments on commit 1a2021c

Please sign in to comment.