-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nextjs,shared): Improve CLERK_API_URL default value (#1955)
* feat(nextjs,shared,remix,gatsby-plugin-clerk): Improve CLERK_API_URL default value * feat(fastify): Improve CLERK_API_URL default value
- Loading branch information
Showing
17 changed files
with
109 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
'@clerk/nextjs': patch | ||
'@clerk/remix': patch | ||
'gatsby-plugin-clerk': patch | ||
'@clerk/shared': patch | ||
'@clerk/fastify': patch | ||
--- | ||
|
||
Improve the default value for `CLERK_API_URL` by utilizing the publishable key to differentiate between local, staging and prod environments. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { constants } from '@clerk/backend'; | ||
import { apiUrlFromPublishableKey } from '@clerk/shared/apiUrlFromPublishableKey'; | ||
|
||
export const API_URL = process.env.CLERK_API_URL || 'https://api.clerk.com'; | ||
export const API_VERSION = process.env.CLERK_API_VERSION || 'v1'; | ||
export const SECRET_KEY = process.env.CLERK_SECRET_KEY || ''; | ||
export const PUBLISHABLE_KEY = process.env.CLERK_PUBLISHABLE_KEY || ''; | ||
export const API_URL = process.env.CLERK_API_URL || apiUrlFromPublishableKey(PUBLISHABLE_KEY); | ||
export const JWT_KEY = process.env.CLERK_JWT_KEY || ''; | ||
|
||
export const { Cookies, Headers } = constants; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
export const API_URL = process.env.CLERK_API_URL || 'https://api.clerk.com'; | ||
import { apiUrlFromPublishableKey } from '@clerk/shared/apiUrlFromPublishableKey'; | ||
|
||
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'; | ||
export const SECRET_KEY = process.env.CLERK_SECRET_KEY || ''; | ||
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,6 @@ poller | |
proxy | ||
underscore | ||
url | ||
react | ||
react | ||
constants | ||
apiUrlFromPublishableKey |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
packages/shared/src/__tests__/apiUrlFromPublishableKey.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { apiUrlFromPublishableKey } from '../apiUrlFromPublishableKey'; | ||
|
||
describe('apiUrlFromPublishableKey', () => { | ||
test('returns the prod api url when given a prod publishable key', async () => { | ||
const apiUrl = apiUrlFromPublishableKey('pk_test_bWFueS1zZWFsLTkwLmNsZXJrLmFjY291bnRzLmRldiQ'); | ||
expect(apiUrl).toBe('https://api.clerk.com'); | ||
}); | ||
|
||
test('returns the prod api url when given a staging publishable key', async () => { | ||
const apiUrl = apiUrlFromPublishableKey('pk_test_aW1tdW5lLWhhd2stNjUuY2xlcmsuYWNjb3VudHNzdGFnZS5kZXYk'); | ||
expect(apiUrl).toBe('https://api.clerkstage.dev'); | ||
}); | ||
|
||
test('returns the prod api url when given a local publishable key', async () => { | ||
const apiUrl = apiUrlFromPublishableKey('pk_test_cGF0aWVudC1nb29zZS01LmNsZXJrLmFjY291bnRzLmxjbGNsZXJrLmNvbSQ'); | ||
expect(apiUrl).toBe('https://api.lclclerk.com'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { LOCAL_API_URL, LOCAL_ENV_SUFFIXES, PROD_API_URL, STAGING_API_URL, STAGING_ENV_SUFFIXES } from './constants'; | ||
import { parsePublishableKey } from './keys'; | ||
|
||
export const apiUrlFromPublishableKey = (publishableKey: string) => { | ||
const frontendApi = parsePublishableKey(publishableKey)?.frontendApi; | ||
if (LOCAL_ENV_SUFFIXES.some(suffix => frontendApi?.endsWith(suffix))) { | ||
return LOCAL_API_URL; | ||
} | ||
if (STAGING_ENV_SUFFIXES.some(suffix => frontendApi?.endsWith(suffix))) { | ||
return STAGING_API_URL; | ||
} | ||
return PROD_API_URL; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export const LEGACY_DEV_INSTANCE_SUFFIXES = ['.lcl.dev', '.lclstage.dev', '.lclclerk.com']; | ||
export const CURRENT_DEV_INSTANCE_SUFFIXES = ['.accounts.dev', '.accountsstage.dev', '.accounts.lclclerk.com']; | ||
export const DEV_OR_STAGING_SUFFIXES = [ | ||
'.lcl.dev', | ||
'.stg.dev', | ||
'.lclstage.dev', | ||
'.stgstage.dev', | ||
'.dev.lclclerk.com', | ||
'.stg.lclclerk.com', | ||
'.accounts.lclclerk.com', | ||
'accountsstage.dev', | ||
'accounts.dev', | ||
]; | ||
export const LOCAL_ENV_SUFFIXES = ['.lcl.dev', 'lclstage.dev', '.lclclerk.com', '.accounts.lclclerk.com']; | ||
export const STAGING_ENV_SUFFIXES = ['.accountsstage.dev']; | ||
export const LOCAL_API_URL = 'https://api.lclclerk.com'; | ||
export const STAGING_API_URL = 'https://api.clerkstage.dev'; | ||
export const PROD_API_URL = 'https://api.clerk.com'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export * from './createDeferredPromise'; | ||
export { isStaging } from './instance'; | ||
export { logErrorInDevMode } from './logErrorInDevMode'; | ||
export { noop } from './noop'; | ||
export * from './runtimeEnvironment'; | ||
export * from './runWithExponentialBackOff'; | ||
export { logErrorInDevMode } from './logErrorInDevMode'; | ||
export * from './runtimeEnvironment'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters