Fix dev protocol scheme collision across worktrees
Make APP_PROTOCOL_SCHEMES per-worktree by incorporating devBundleIdSuffix (e.g. t3code-dev-t3code), matching the existing per-worktree APP_BUNDLE_ID. Pass the scheme to the Electron process via T3CODE_DESKTOP_PROTOCOL_SCHEME so DesktopCloudAuth uses the correct worktree-specific scheme for OAuth callbacks. This prevents LSSetDefaultHandlerForURLScheme from stealing callbacks between simultaneously running dev instances.
This commit is contained in:
3 files changed
+15
-4
No files matched your search
@@ -29,7 +29,9 @@ export const APP_DISPLAY_NAME = isDevelopment ? "T3 Code (Dev)" : "T3 Code (Alph
|
||||
export const APP_BUNDLE_ID = isDevelopment
|
||||
? `com.t3tools.t3code.dev.${devBundleIdSuffix || "local"}`
|
||||
: "com.t3tools.t3code";
|
||||
const APP_PROTOCOL_SCHEMES = isDevelopment ? ["t3code-dev"] : ["t3code"];
|
||||
const APP_PROTOCOL_SCHEMES = isDevelopment
|
||||
? [`t3code-dev-${devBundleIdSuffix || "local"}`]
|
||||
: ["t3code"];
|
||||
const LAUNCHER_VERSION = 10;
|
||||
const defaultIconPath = join(desktopDir, "resources", "icon.icns");
|
||||
const developmentMacIconPngPath = join(repoRoot, "assets", "dev", "blueprint-macos-1024.png");
|
||||
@@ -106,6 +108,7 @@ function writeDevelopmentLauncherScript(targetBinaryPath, electronBinaryPath) {
|
||||
["T3CODE_OTLP_TRACES_URL", process.env.T3CODE_OTLP_TRACES_URL],
|
||||
["T3CODE_OTLP_EXPORT_INTERVAL_MS", process.env.T3CODE_OTLP_EXPORT_INTERVAL_MS],
|
||||
["T3CODE_DESKTOP_APP_USER_MODEL_ID", APP_BUNDLE_ID],
|
||||
["T3CODE_DESKTOP_PROTOCOL_SCHEME", APP_PROTOCOL_SCHEMES[0]],
|
||||
["T3CODE_DESKTOP_PROTOCOL_REGISTRATION_MANAGED", "1"],
|
||||
["T3CODE_DESKTOP_PROTOCOL_CALLBACK_URL", protocolCallbackUrl],
|
||||
].filter((entry) => typeof entry[1] === "string" && entry[1].trim().length > 0);
|
||||
@@ -116,7 +119,7 @@ function writeDevelopmentLauncherScript(targetBinaryPath, electronBinaryPath) {
|
||||
...envEntries.map(([name, value]) => `export ${name}=${shellSingleQuote(value)}`),
|
||||
'for arg in "$@"; do',
|
||||
' case "$arg" in',
|
||||
" t3code-dev://auth/callback*)",
|
||||
` ${APP_PROTOCOL_SCHEMES[0]}://auth/callback*)`,
|
||||
' if [ -n "$T3CODE_DESKTOP_PROTOCOL_CALLBACK_URL" ]; then',
|
||||
' /usr/bin/curl -fsS --max-time 2 -X POST --data-binary "$arg" "$T3CODE_DESKTOP_PROTOCOL_CALLBACK_URL" >/dev/null 2>&1 && exit 0',
|
||||
" fi",
|
||||
|
||||
@@ -52,6 +52,10 @@ export class DesktopCloudAuth extends Context.Service<DesktopCloudAuth, DesktopC
|
||||
) {}
|
||||
|
||||
export function resolveCloudAuthCallbackScheme(input: { readonly isDevelopment: boolean }): string {
|
||||
if (input.isDevelopment) {
|
||||
const override = process.env.T3CODE_DESKTOP_PROTOCOL_SCHEME?.trim();
|
||||
if (override) return override;
|
||||
}
|
||||
return input.isDevelopment ? DEVELOPMENT_CLOUD_AUTH_CALLBACK_SCHEME : CLOUD_AUTH_CALLBACK_SCHEME;
|
||||
}
|
||||
|
||||
|
||||
@@ -124,11 +124,15 @@ In **Clerk Dashboard > Native applications**, enable native application support
|
||||
entries under the mobile SSO redirect allowlist:
|
||||
|
||||
```text
|
||||
t3code-dev://auth/callback
|
||||
t3code-dev-<suffix>://auth/callback
|
||||
t3code://auth/callback
|
||||
```
|
||||
|
||||
The first entry is for local desktop development. The second is for packaged desktop builds.
|
||||
The first entry is for local desktop development. The `<suffix>` is the lowercased alphanumeric
|
||||
form of the repository root directory name (e.g. `t3code-dev-t3code` for a checkout named
|
||||
`t3-code`). Each worktree gets a unique scheme so multiple simultaneous dev instances do not steal
|
||||
OAuth callbacks from each other. Add each worktree's scheme to the allowlist. The second entry is
|
||||
for packaged desktop builds.
|
||||
The app also adds a request-scoped `t3_state` query parameter and validates it on callback. Initial
|
||||
sign-in and linked-account OAuth flows both return through this bridge. The desktop provider keeps
|
||||
Clerk's stock profile component, replaces its renderer-page callback with the custom-scheme callback,
|
||||
|
||||
Reference in new issue
Block a user