fix(expo): Make publishableKey prop required and remove env var fallb…#7655
Conversation
🦋 Changeset detectedLatest commit: 7cae015 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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
…uire-publishablekey-prop
📝 WalkthroughWalkthroughThe PR makes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/expo/src/provider/singleton/createClerkInstance.ts (1)
30-40: Add regression tests for requiredpublishableKeybehavior.This is a breaking change removing env fallbacks; please add/adjust tests to cover missing-key errors and instance reuse to prevent regressions before merge. As per coding guidelines, add tests for this change.
wobsoriano
left a comment
There was a problem hiding this comment.
Looking good! Let's provide a clear migration instruction
Co-authored-by: Robert Soriano <sorianorobertc@gmail.com>
…uire-publishablekey-prop
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In @.changeset/kadi-env-var-fix.md:
- Around line 11-16: Replace the unchecked non-null assertion on
process.env.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY by validating it before use: read
process.env.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY into publishableKey, check that
publishableKey is defined/non-empty and if not either throw a clear error (with
context) or provide a safe fallback, and only then pass publishableKey into
<ClerkProvider> so the app won't crash at runtime; locate the usage by the
publishableKey variable and the <ClerkProvider> component to apply the check.
| ```tsx | ||
| const publishableKey = process.env.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY!; | ||
|
|
||
| <ClerkProvider publishableKey={publishableKey}> | ||
| {/* Your app */} | ||
| </ClerkProvider> |
There was a problem hiding this comment.
Add validation to prevent undefined publishableKey.
The migration example uses the non-null assertion operator (!) without validation. If EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY is not set, the app will crash—exactly the issue this PR aims to prevent.
✅ Proposed fix with proper error handling
-const publishableKey = process.env.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY!;
+const publishableKey = process.env.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY;
+
+if (!publishableKey) {
+ throw new Error('Missing Publishable Key. Please set EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY in your .env file.');
+}
<ClerkProvider publishableKey={publishableKey}>
{/* Your app */}
</ClerkProvider>🤖 Prompt for AI Agents
In @.changeset/kadi-env-var-fix.md around lines 11 - 16, Replace the unchecked
non-null assertion on process.env.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY by
validating it before use: read process.env.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY
into publishableKey, check that publishableKey is defined/non-empty and if not
either throw a clear error (with context) or provide a safe fallback, and only
then pass publishableKey into <ClerkProvider> so the app won't crash at runtime;
locate the usage by the publishableKey variable and the <ClerkProvider>
component to apply the check.
|
!allow-major |
wobsoriano
left a comment
There was a problem hiding this comment.
Awesome, thank you for fixing this!
|
Hi @SarahSoutoul I realized this morning that we will need a docs update because of this change, as the docs currently show examples where the publishable key is not passed to the clerkprovider. That is now required. Added a docs PR here: |
Description
https://linear.app/clerk/issue/MOBILE-393/remove-env-var-fallback-require-publishablekey-prop
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.