Repository navigation
fix(init): stop iOS setup when the app's publishable key belongs to another application - #639
seanperez29 wants to merge 3 commits into
Conversation
…nother application A repository's Clerk link is shared by every project in it, so an existing iOS or macOS app built with application B's publishable key could be set up against the linked application A: init registered its Bundle ID and enabled Native API on A. Before any prompt, remote read, or change, init now reads the key the app passes to Clerk.configure in the configuration it sets up and compares it with the linked application's instances. A key that matches none of them stops setup with a usage error, naming the key's application when the account can see it. With --json it's an input-required status with link.flag "--relink", the key's application as link.requested, and next steps to relink or change the app's key. A production key of the linked application continues with a note, and a key the CLI can't read never blocks; the result's new configuredKey field says whether the key was verified. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: d8c176c 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 |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
…emedy Review-loop changes to the iOS publishable key check: - Check every configuration setup changes (Debug and Release, or --xcode-configuration), not only the first; the JSON result reports configuredKeys per configuration and the stop lists every mismatched configuration in link.publishableKeys. - Offer --relink only when it fixes every configuration: each key was read, none uses the link, and they're one key or keys of one known application. Otherwise ask to change the keys, naming configurations whose key couldn't be checked. - Name the linked application's key for the same environment in the remedy, keep this run's setup flags and an explicit --framework in the suggested command, and describe what relinking does outside Git. - Stop when the linked application can't be read instead of skipping the check; route listApplications through NativeAPI; reuse profileLabel and InstanceEnvironment; print the stop as compact JSON. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>


What
clerk initon an existing iOS or macOS app now checks the publishable key the app passes toClerk.configureagainst the linked Clerk application before it changes anything. If a configuration's key belongs to a different application, setup stops instead of setting up the linked one.Why
A repository's Clerk link is shared by every project in the repository. When a repository is linked to application A but its iOS app is built with application B's publishable key,
initreused A's link without returningapplication-required, then registered the Bundle ID and enabled Native API on A. The app still signs in against B, so the registration does nothing for it.assertApplicationChosenonly runs for new projects and starters, and the clerk-swift skill only compares keys when the CLI returnsapplication-required, so agents couldn't catch it either.Steps to reproduce
clerk link --app <A>), with an existing iOS app inside it.Clerk.configure(publishableKey: "pk_test_…")with a development key of application B.clerk init --jsonfrom the app's folder.Before this change, init reused A's link, registered the app's Bundle ID on A, and enabled Native API on A. After it, init stops before any change with the status below.
Output after the change
These samples come from the unit-test fixtures in
configured-key.test.ts(a linked application "Linked (app_test)" and another application "Other (app_other)"), with the scope path shortened. Keys are compared, never printed.JSON, relink offered (both configurations use B's key)
{ "status": "input-required", "appIntegrationComplete": false, "link": { "flag": "--relink", "question": "This app is configured with Other (app_other)'s publishable key, but /Users/me/acme is linked to Linked (app_test). Switch the link to Other (app_other), or keep Linked (app_test) and change the app's key?", "issue": "/Users/me/acme is linked to Linked (app_test), but the publishable key MyApp passes to Clerk.configure in Debug and Release (from a string literal in MyApp/MyAppApp.swift) belongs to Other (app_other). Setting up Linked (app_test) would register this app on an application it doesn't sign in to, so no setup was applied. To set up Other (app_other) instead, run `clerk init --app app_other --json --relink` (this switches the link for every project in /Users/me/acme). To keep Linked (app_test), change the key for Debug and Release to Linked (app_test)'s development publishable key, then rerun clerk init.", "current": { "appId": "app_test", "appName": "Linked" }, "requested": "app_other", "scope": "/Users/me/acme", "publishableKeys": [ { "configuration": "Debug", "source": "a string literal in MyApp/MyAppApp.swift", "frontendApiHost": "other-app-42.clerk.accounts.dev", "application": { "appId": "app_other", "appName": "Other" } }, { "configuration": "Release", "source": "a string literal in MyApp/MyAppApp.swift", "frontendApiHost": "other-app-42.clerk.accounts.dev", "application": { "appId": "app_other", "appName": "Other" } } ] }, "next": [ "If the user wants Other (app_other), run `clerk init --app app_other --json --relink`.", "If the user wants to keep Linked (app_test), change the key for Debug and Release to Linked (app_test)'s development publishable key where Clerk.configure gets it (`clerk apps list --json` lists the keys), then rerun clerk init." ] }JSON, no relink (Debug uses A's key, Release a key of an application the CLI can't list)
{ "status": "input-required", "appIntegrationComplete": false, "link": { "question": "This app's configurations use publishable keys from different applications, and /Users/me/acme is linked to Linked (app_test). Which application should the app use?", "issue": "/Users/me/acme is linked to Linked (app_test), but the publishable key MyApp passes to Clerk.configure in Release (from the Info.plist entry ClerkPublishableKey, set by the CLERK_PUBLISHABLE_KEY build setting) belongs to an application whose Frontend API is clerk.other.example, which isn't among the applications the CLI could list. Debug uses Linked (app_test)'s key. clerk init sets up one application for every configuration it changes, so no setup was applied. To keep Linked (app_test), change the key for Release to Linked (app_test)'s production publishable key, then rerun clerk init.", "current": { "appId": "app_test", "appName": "Linked" }, "scope": "/Users/me/acme", "publishableKeys": [ { "configuration": "Release", "source": "the Info.plist entry ClerkPublishableKey, set by the CLERK_PUBLISHABLE_KEY build setting", "frontendApiHost": "clerk.other.example" } ] }, "next": [ "clerk init sets up one application for all the configurations it changes, so ask the user which application the app should use.", "If the user wants to keep Linked (app_test), change the key for Release to Linked (app_test)'s production publishable key where Clerk.configure gets it (`clerk apps list --json` lists the keys), then rerun clerk init." ] }Human mode (usage error, exit 2)
How
init/ios/configured-key.ts, called fromrunAppleInitright after the Xcode inspection, before setup's questions or any change to the project or Clerk. It reusesconfiguredPublishableKeyandscanSwiftSources(today used byclerk doctor's production checks), unchanged. Those read a Swift string literal, or an Info.plist entry that's a literal or a$(BUILD_SETTING), and report anything else as unresolved with a reason.--xcode-configuration) and compares each key's Frontend API host with the linked application's instances, from the Platform API application the CLI already reads. Keys are never printed. If the linked application can't be read, init stops with that error, since setup needs it anyway.listApplications, now part ofNativeAPI), otherwise the key's Frontend API host. Keeping the link means passing the linked application's key for the same environment (development or production) toClerk.configure.clerk init --app <id>with this run's setup options, plus--relinkfor agents) is offered only when it's sure to fix every configuration: every configuration's key was read, none uses the linked application, and they're all the same key or keys of the same known application. Otherwise the stop asks to change the keys, and names any configuration whose key couldn't be checked.--json, the stop is aninput-requiredstatus shaped like the existing link stops:link: { flag, question, issue, current, requested, scope, publishableKeys: [{ configuration, source, frontendApiHost, application }] }, plusnext.flagis--relinkonly when relinking is offered, andrequestedandapplicationappear only when the key's application is known.--xcode-configuration) signs in against production.#if, several calls): never blocks. The JSON result gets a newconfiguredKeysfield with one entry per configuration (verifiedwithinstanceandsource, orunverifiedwithreason), and the human preview notes unverified keys, once per reason.--starterapp and an unchanged starter, since setup writes the linked application's key into those itself, and for dry runs.--framework iosor--framework macos(theapplication-requiredcontinuation for existing projects keeps it as well). Outside a Git repository, the message says what relinking really does to the link.Testing
configured-key.test.ts: an agent's JSON stop with the key's application named, and nothing registered, enabled, or written; the human stop when the application isn't visible; a failed application lookup; development and production keys of the linked application; an unreadable key reported asunverified, with one note for Debug and Release; Debug on the linked application with Release on another; keys of two applications, unlisted keys, and a listed plus an unlisted key (no relink); keys of the same other application (relink); a configuration whose key couldn't be checked (no relink); a failed read of the linked application; unchanged starters, including a rerun that adds the sign-in view.index-ios.test.ts:initpasses the link's scope, what relinking does outside a repository, and relink commands that keep the setup options and an explicit--framework.bun run typecheck,bun run lint,bun run format:check, andbun run testpass on 98a4a91.scripts/apple-setup/verify-*.tsonly gained alistApplicationsstub for the widerNativeAPItype. They callprepareSetup,applySetup, andauditProductiondirectly, so the key check doesn't run in them, and they weren't run.Notes
Clerk.configure(publishableKey:)call. So the stop only fires on a definite mismatch, and the rest get a note.configuredKeysfield andinput-requiredshape are additive (not breaking under the--jsoncontract), and the change is a fix, so the changeset is a patch.Clerk.configurecall that sits only in a file compiled for another platform, platform-specific Info.plist entries such asClerkPublishableKey-macos, and a linked instance with no publishable key.skills/clerk-swift/references/prebuilt.mdandcustom.mdonly coverapplication-requiredand should get a line forinput-requiredwithlink.publishableKeys. The docs' iOS setup prompt already compares keys for existing projects, and itslink.flag: "--relink"rule covers this status.🤖 Generated with Claude Code