-
Notifications
You must be signed in to change notification settings - Fork 252
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): Introduce getClerkInstance to access/create a Clerk instance #3420
feat(clerk-expo): Introduce getClerkInstance to access/create a Clerk instance #3420
Conversation
🦋 Changeset detectedLatest commit: 8eb1154 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
58266b6
to
b9fce29
Compare
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.
🔥
.changeset/calm-wasps-accept.md
Outdated
const clerkInstance = createClerkClient({ publishableKey: 'xxxx' }) | ||
|
||
// Be sure to pass the new instance to ClerkProvider to avoid running multiple instances of Clerk in your application | ||
<ClerkProvider Clerk={clerkInstance}> |
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.
so going forward in Expo apps, every developer should create this new Clerk instance and pass it in if they want to be able to access it outside of React right?
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.
Yeah that's right they should create the new instance with createClerkClient
Is this preferable over exporting the singleton? Seems like we're introducing a footgun if someone forgets to pass their Clerk instance to |
@BRKalow the exported |
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.
Revisit naming to not conflict with clerk/backend naming, and make sure we don't make it possible to create two clerk instances.
ac33c7d
to
4492bba
Compare
This request comes up with React/Next/Remix apps when using tools like Tanstack Query or even just Axios/Fetch. We see this request with even Chrome Extensions. We can use |
4492bba
to
06903f9
Compare
cd88598
to
533524b
Compare
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.
❓ Should we add the getClerkInstance
in the rest of our frontend-only packages (eg chrome-extension) to support the same use case?
Also, should we add it to the server-related packages (eg nextjs, remix) as a way to retrieve the default backend clerkClient instead of using the exported clerkClient
?
@@ -11,29 +13,56 @@ Clerk.sdkMetadata = { | |||
|
|||
const KEY = '__clerk_client_jwt'; | |||
|
|||
/** | |||
* @deprecated Use `getClerkInstance` instead. `Clerk` will be removed in the next major version. |
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.
🙃 typo, clerk
should be with lower case to match the actual export.
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.
So i looked at this again, turns out the exported variable from the package is Clerk
so the initial comment is correct
This reverts commit fe61d21.
…nd-to-the-token-outside-of
Description
Introduce
getClerkInstance
to avoid importing the Clerk class from clerk-js manually.This enables developers to create and access a Clerk instance in their application outside of React.
⚠Note:
getClerkInstance()
with different publishable keys will create a new Clerk instance.getClerkInstance
is called without a publishable key, and ClerkProvider has not rendered yet, an error will be thrownChecklist
npm test
runs as expected.npm run build
runs as expected.Type of change