-
Notifications
You must be signed in to change notification settings - Fork 402
chore(nextjs): Display keyless prompt until .clerk/ is removed
#4940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
panteliselef
merged 15 commits into
main
from
elef/actls-65-nextjs-show-claiming-success-message-when-env-keys-and-local
Jan 21, 2025
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c176671
feat(nextjs): Run on keyless until after you dismiss
panteliselef 0a51adb
feat(nextjs): Run on keyless until after you dismiss 2
panteliselef ae68384
Delete `.clerk/` on dismiss
panteliselef 8909217
fire dismiss and reload
panteliselef f5bc623
wip
panteliselef 9d603e8
improve code quality in keyless-node
panteliselef 85fc605
fix issue from merging
panteliselef 6b5d1e4
cleanup
panteliselef 0499bb9
improve code quality
panteliselef 8c32b37
changeset
panteliselef cea4d7b
bump bundlewatch
panteliselef 27f72fe
error handling on `rmSync`
panteliselef ef6a49f
Update packages/nextjs/src/server/keyless-node.ts
panteliselef 14580fd
prefix types with `__internal_keyless_`
panteliselef 1b36a4a
Merge branch 'main' into elef/actls-65-nextjs-show-claiming-success-m…
panteliselef File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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/clerk-js': minor | ||
| '@clerk/nextjs': minor | ||
| '@clerk/types': minor | ||
| --- | ||
|
|
||
| Display keyless prompt until the developer manually dismisses it. |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -4,11 +4,13 @@ import React from 'react'; | |
|
|
||
| import { PromisifiedAuthProvider } from '../../client-boundary/PromisifiedAuthProvider'; | ||
| import { getDynamicAuthData } from '../../server/buildClerkProps'; | ||
| import { safeParseClerkFile } from '../../server/keyless-node'; | ||
| import type { NextClerkProviderProps } from '../../types'; | ||
| import { canUseKeyless } from '../../utils/feature-flags'; | ||
| import { mergeNextClerkPropsWithEnv } from '../../utils/mergeNextClerkPropsWithEnv'; | ||
| import { isNext13 } from '../../utils/sdk-versions'; | ||
| import { ClientClerkProvider } from '../client/ClerkProvider'; | ||
| import { deleteKeylessAction } from '../keyless-actions'; | ||
| import { buildRequestLike, getScriptNonceFromHeader } from './utils'; | ||
|
|
||
| const getDynamicClerkState = React.cache(async function getDynamicClerkState() { | ||
|
|
@@ -69,30 +71,36 @@ export async function ClerkProvider( | |
| </ClientClerkProvider> | ||
| ); | ||
|
|
||
| const shouldRunAsKeyless = !propsWithEnvs.publishableKey && canUseKeyless; | ||
| const runningWithClaimedKeys = propsWithEnvs.publishableKey === safeParseClerkFile()?.publishableKey; | ||
| const shouldRunAsKeyless = (!propsWithEnvs.publishableKey || runningWithClaimedKeys) && canUseKeyless; | ||
|
|
||
| if (shouldRunAsKeyless) { | ||
| // NOTE: Create or read keys on every render. Usually this means only on hard refresh or hard navigations. | ||
| const newOrReadKeys = await import('../../server/keyless-node.js').then(mod => mod.createOrReadKeyless()); | ||
|
|
||
| if (newOrReadKeys) { | ||
| const KeylessCookieSync = await import('../client/keyless-cookie-sync.js').then(mod => mod.KeylessCookieSync); | ||
| output = ( | ||
| <KeylessCookieSync {...newOrReadKeys}> | ||
| <ClientClerkProvider | ||
| {...mergeNextClerkPropsWithEnv({ | ||
| ...rest, | ||
| publishableKey: newOrReadKeys.publishableKey, | ||
| __internal_claimKeylessApplicationUrl: newOrReadKeys.claimUrl, | ||
| __internal_copyInstanceKeysUrl: newOrReadKeys.apiKeysUrl, | ||
| })} | ||
| nonce={await generateNonce()} | ||
| initialState={await generateStatePromise()} | ||
| > | ||
| {children} | ||
| </ClientClerkProvider> | ||
| </KeylessCookieSync> | ||
| const clientProvider = ( | ||
| <ClientClerkProvider | ||
| {...mergeNextClerkPropsWithEnv({ | ||
| ...rest, | ||
| publishableKey: newOrReadKeys.publishableKey, | ||
| __internal_keyless_claimKeylessApplicationUrl: newOrReadKeys.claimUrl, | ||
| __internal_keyless_copyInstanceKeysUrl: newOrReadKeys.apiKeysUrl, | ||
| __internal_keyless_dismissPrompt: runningWithClaimedKeys ? deleteKeylessAction : undefined, | ||
| })} | ||
| nonce={await generateNonce()} | ||
| initialState={await generateStatePromise()} | ||
| > | ||
| {children} | ||
| </ClientClerkProvider> | ||
| ); | ||
|
|
||
| if (runningWithClaimedKeys) { | ||
| output = clientProvider; | ||
| } else { | ||
| output = <KeylessCookieSync {...newOrReadKeys}>{clientProvider}</KeylessCookieSync>; | ||
| } | ||
|
Comment on lines
+99
to
+103
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We want to keep rendering the Keyless prompt which is controlled by the props passed to |
||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.