-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1806 from clerkinc/revert-1767
fix(nextjs,shared): Revert "Use `use client` directive to support sha…
- Loading branch information
Showing
29 changed files
with
14,415 additions
and
11,011 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,7 @@ | ||
--- | ||
'@clerk/backend': patch | ||
'@clerk/shared': patch | ||
'@clerk/nextjs': patch | ||
--- | ||
|
||
Temporarily revert internal change to resolve RSC-related errors |
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
function wait(ms: number) { | ||
return new Promise(res => setTimeout(res, ms)); | ||
} | ||
|
||
const MAX_NUMBER_OF_RETRIES = 5; | ||
|
||
// TODO: Move this to @clerk/shared and reuse it with @clerk/clerk-js | ||
export async function callWithRetry<T>( | ||
fn: (...args: unknown[]) => Promise<T>, | ||
attempt = 1, | ||
maxAttempts = MAX_NUMBER_OF_RETRIES, | ||
): Promise<T> { | ||
try { | ||
return await fn(); | ||
} catch (e) { | ||
if (attempt >= maxAttempts) { | ||
throw e; | ||
} | ||
await wait(2 ** attempt * 100); | ||
|
||
return callWithRetry(fn, attempt + 1); | ||
} | ||
} |
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,15 @@ | ||
/* | ||
* This module will contain functionality that will be copied | ||
* from @clerk/shared and will be replaced by imports when the | ||
* bundling issue is fixed. | ||
*/ | ||
export { isDevelopmentFromApiKey, isProductionFromApiKey, isStaging } from './instance'; | ||
|
||
export { addClerkPrefix, getScriptUrl, getClerkJsMajorVersionOrTag } from './url'; | ||
export { callWithRetry } from './callWithRetry'; | ||
|
||
// TODO: replace it with @clerk/shared errorThrower.throwMissingPublishableKeyError() | ||
export const missingPublishableKeyErrorMessage = `Missing publishableKey. You can get your key at https://dashboard.clerk.com/last-active?path=api-keys.`; | ||
|
||
export { isDevOrStagingUrl } from './isDevOrStagingUrl'; | ||
export { buildPublishableKey, isPublishableKey, parsePublishableKey } from './parsePublishableKey'; |
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,16 @@ | ||
export function isDevelopmentFromApiKey(apiKey: string): boolean { | ||
return apiKey.startsWith('test_') || apiKey.startsWith('sk_test_'); | ||
} | ||
|
||
export function isProductionFromApiKey(apiKey: string): boolean { | ||
return apiKey.startsWith('live_') || apiKey.startsWith('sk_live_'); | ||
} | ||
|
||
export function isStaging(frontendApi: string): boolean { | ||
return ( | ||
frontendApi.endsWith('.lclstage.dev') || | ||
frontendApi.endsWith('.stgstage.dev') || | ||
frontendApi.endsWith('.clerkstage.dev') || | ||
frontendApi.endsWith('.accountsstage.dev') | ||
); | ||
} |
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,35 @@ | ||
// TODO: use the same function from @clerk/shared once treeshakable | ||
function createDevOrStagingUrlCache() { | ||
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', | ||
]; | ||
|
||
const devOrStagingUrlCache = new Map<string, boolean>(); | ||
|
||
return { | ||
isDevOrStagingUrl: (url: string | URL): boolean => { | ||
if (!url) { | ||
return false; | ||
} | ||
|
||
const hostname = typeof url === 'string' ? url : url.hostname; | ||
let res = devOrStagingUrlCache.get(hostname); | ||
if (res === undefined) { | ||
res = DEV_OR_STAGING_SUFFIXES.some(s => hostname.endsWith(s)); | ||
devOrStagingUrlCache.set(hostname, res); | ||
} | ||
return res; | ||
}, | ||
}; | ||
} | ||
|
||
const { isDevOrStagingUrl } = createDevOrStagingUrlCache(); | ||
export { isDevOrStagingUrl }; |
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,56 @@ | ||
import type { PublishableKey } from '@clerk/types'; | ||
|
||
const PUBLISHABLE_KEY_LIVE_PREFIX = 'pk_live_'; | ||
const PUBLISHABLE_KEY_TEST_PREFIX = 'pk_test_'; | ||
|
||
// This regex matches the publishable like frontend API keys (e.g. foo-bar-13.clerk.accounts.dev) | ||
const PUBLISHABLE_FRONTEND_API_DEV_REGEX = /^(([a-z]+)-){2}([0-9]{1,2})\.clerk\.accounts([a-z.]*)(dev|com)$/i; | ||
|
||
export function buildPublishableKey(frontendApi: string): string { | ||
const keyPrefix = PUBLISHABLE_FRONTEND_API_DEV_REGEX.test(frontendApi) | ||
? PUBLISHABLE_KEY_TEST_PREFIX | ||
: PUBLISHABLE_KEY_LIVE_PREFIX; | ||
return `${keyPrefix}${btoa(`${frontendApi}$`)}`; | ||
} | ||
|
||
export function parsePublishableKey(key: string | undefined): PublishableKey | null { | ||
key = key || ''; | ||
|
||
if (!isPublishableKey(key)) { | ||
return null; | ||
} | ||
|
||
const instanceType = key.startsWith(PUBLISHABLE_KEY_LIVE_PREFIX) ? 'production' : 'development'; | ||
|
||
let frontendApi = isomorphicAtob(key.split('_')[2]); | ||
|
||
if (!frontendApi.endsWith('$')) { | ||
return null; | ||
} | ||
|
||
frontendApi = frontendApi.slice(0, -1); | ||
|
||
return { | ||
instanceType, | ||
frontendApi, | ||
}; | ||
} | ||
|
||
export function isPublishableKey(key: string) { | ||
key = key || ''; | ||
|
||
const hasValidPrefix = key.startsWith(PUBLISHABLE_KEY_LIVE_PREFIX) || key.startsWith(PUBLISHABLE_KEY_TEST_PREFIX); | ||
|
||
const hasValidFrontendApiPostfix = isomorphicAtob(key.split('_')[2] || '').endsWith('$'); | ||
|
||
return hasValidPrefix && hasValidFrontendApiPostfix; | ||
} | ||
|
||
const isomorphicAtob = (data: string) => { | ||
if (typeof atob !== 'undefined' && typeof atob === 'function') { | ||
return atob(data); | ||
} else if (typeof globalThis !== 'undefined' && globalThis.Buffer) { | ||
return new globalThis.Buffer(data, 'base64').toString(); | ||
} | ||
return data; | ||
}; |
Oops, something went wrong.