diff --git a/apps/desktop/scripts/electron-launcher.mjs b/apps/desktop/scripts/electron-launcher.mjs index 8f20001bbb..e7e0cb3ffe 100644 --- a/apps/desktop/scripts/electron-launcher.mjs +++ b/apps/desktop/scripts/electron-launcher.mjs @@ -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", diff --git a/apps/desktop/src/app/DesktopCloudAuth.ts b/apps/desktop/src/app/DesktopCloudAuth.ts index 732de27b9a..67de661eb6 100644 --- a/apps/desktop/src/app/DesktopCloudAuth.ts +++ b/apps/desktop/src/app/DesktopCloudAuth.ts @@ -52,6 +52,10 @@ export class DesktopCloudAuth extends Context.Service Native applications**, enable native application support entries under the mobile SSO redirect allowlist: ```text -t3code-dev://auth/callback +t3code-dev-://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 `` 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,