-
Notifications
You must be signed in to change notification settings - Fork 253
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
feat(clerk-expo): Support swapping publishableKey at runtime #1655
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@clerk/clerk-js': patch | ||
'@clerk/clerk-react': patch | ||
'@clerk/clerk-expo': minor | ||
--- | ||
|
||
Support swapping the Clerk publishableKey at runtime to allow users to toggle the instance being used. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ export function ClerkProvider(props: ClerkProviderProps): JSX.Element { | |
return ( | ||
//@ts-expect-error | ||
<ClerkReactProvider | ||
// Force reset the state when the provided key changes, this ensures that the provider does not retain stale state. See JS-598 for additional context. | ||
key={key} | ||
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. ❓I think that there is 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. The use of key here is intentional to force react to remount the component and wipe away any stale state from the previous instance. As far as I can tell, by passing the clerk instance below we remove the need to pass the publishableKey as a prop |
||
{...rest} | ||
Clerk={buildClerk({ key, tokenCache })} | ||
standardBrowser={!isReactNative()} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,8 +87,9 @@ export default class IsomorphicClerk { | |
static getOrCreateInstance(options: IsomorphicClerkOptions) { | ||
// During SSR: a new instance should be created for every request | ||
// During CSR: use the cached instance for the whole lifetime of the app | ||
// Also will recreate the instance if the provided Clerk instance changes | ||
// This method should be idempotent in both scenarios | ||
if (!inClientSide() || !this.#instance) { | ||
if (!inClientSide() || !this.#instance || (options.Clerk && this.#instance.Clerk !== options.Clerk)) { | ||
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. Without this change, there was no way to forcibly reset the created 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. This makes sense 👍🏻 |
||
this.#instance = new IsomorphicClerk(options); | ||
} | ||
return this.#instance; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is specified as a public readonly property, but we weren't setting it anywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm almost sure this is not used anywhere - @panteliselef , any chance this is needed by the multidomains feature?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using it in another spot in this PR to check for a new key, but let me know if we don't want to set this for some reason!