-
Notifications
You must be signed in to change notification settings - Fork 283
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
Merged
panteliselef
merged 10 commits into
main
from
elef/sdk-1724-figure-out-how-we-should-respond-to-the-token-outside-of
Jun 4, 2024
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0c6e451
feat(expo): Introduce `createClerkClient` to avoid importing the Cler…
panteliselef 3f52dcd
feat(expo): Add changeset
panteliselef e6be841
chore(clerk-expo): Use `getClerkInstance`
panteliselef 9bbd1a1
chore(clerk-expo): Throw error when calling `getClerkInstance()`
panteliselef e778f64
chore(clerk-expo): Add errorThrower
panteliselef 533524b
fix(clerk-expo): Expo env
panteliselef fe61d21
chore(clerk-expo): fix type
panteliselef a4fbaa2
Revert "chore(clerk-expo): fix type"
panteliselef 78be5ac
chore(clerk-expo): fix pk detection
panteliselef 8eb1154
Merge branch 'main' into elef/sdk-1724-figure-out-how-we-should-respo…
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 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,36 @@ | ||
--- | ||
'@clerk/clerk-expo': minor | ||
--- | ||
|
||
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. | ||
```tsx | ||
import { ClerkProvider, getClerkInstance } from "@clerk/expo" | ||
|
||
const clerkInstance = getClerkInstance({ publishableKey: 'xxxx' }) | ||
|
||
// Always pass the `publishableKey` to `ClerkProvider` | ||
<ClerkProvider publishableKey={'xxxx'}> | ||
... | ||
</ClerkProvider> | ||
|
||
// Somewhere in your code, outside of React you can do | ||
const token = await clerkInstance.session?.getToken(); | ||
fetch('http://example.com/', {headers: {Authorization: token }) | ||
``` | ||
```tsx | ||
import { ClerkProvider, getClerkInstance } from "@clerk/expo" | ||
|
||
// Always pass the `publishableKey` to `ClerkProvider` | ||
<ClerkProvider publishableKey={'xxxx'}> | ||
... | ||
</ClerkProvider> | ||
|
||
// If you sure that this code will run after the ClerkProvider has rendered then you can use `getClerkIntance` without options | ||
const token = await getClerkInstance().session?.getToken(); | ||
fetch('http://example.com/', {headers: {Authorization: token }) | ||
|
||
``` | ||
Attention: If `getClerkInstance` is called without a publishable key, and ClerkProvider has not rendered yet, an error will be thrown | ||
|
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,5 @@ | ||
import { buildErrorThrower } from '@clerk/shared/error'; | ||
|
||
const errorThrower = buildErrorThrower({ packageName: PACKAGE_NAME }); | ||
|
||
export { errorThrower }; |
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
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.
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