Skip to content

🐛 Spotify login broken in production Tauri build #1

@BunsDev

Description

@BunsDev

Description

Spotify PKCE login fails in the production Tauri desktop build. After authenticating with Spotify, the redirect goes to a dead URL and the OAuth callback is never handled.

Root Cause

In lib/spotify-auth.ts, the getRedirectUri() function returns http://127.0.0.1:3080/ for Tauri builds:

function getRedirectUri(): string {
  const origin = window.location.origin
  if (isTauri() || origin.startsWith("tauri://")) {
    return "http://127.0.0.1:3080/"
  }
  // ...
}

This works in dev mode (where a Next.js dev server runs on port 3080), but in a production build there is no server on 127.0.0.1:3080 — the Tauri webview serves content from a custom protocol (tauri://localhost). Spotify redirects to a dead URL and the callback code is never exchanged for tokens.

Additionally, http://127.0.0.1:3080/ must be registered in the Spotify Developer Dashboard as a valid redirect URI for the app's Client ID.

Steps to Reproduce

  1. Open KnotCode desktop app (production .dmg build)
  2. Go to Settings → Plugins → Spotify
  3. Click "Connect Spotify"
  4. Authenticate on Spotify's page
  5. Observe: Redirect goes to 127.0.0.1:3080 → blank/error page. Token is never saved.

Expected Behavior

After Spotify auth, the user should be redirected back to the app, the auth code should be exchanged for tokens, and Spotify playback should work.

Possible Solutions

  1. Deep link handler (recommended): Register a custom URL scheme (e.g. knotcode://spotify/callback) with Tauri, set it as the Spotify redirect URI, and handle the callback in the app
  2. Localhost HTTP listener: Spin up a temporary HTTP server on a random port in the Tauri backend (Rust side) to catch the redirect — similar to how gh auth login works
  3. Spotify Device Flow: If available, use device code flow instead of PKCE redirect (avoids the redirect problem entirely)

Affected Files

  • lib/spotify-auth.tsgetRedirectUri(), startSpotifyLogin(), handleSpotifyCallback()
  • src-tauri/tauri.conf.json — may need deep link plugin config
  • Spotify Developer Dashboard — redirect URI whitelist

Environment

  • KnotCode v1.0.0 (production Tauri build)
  • macOS (Apple Silicon)
  • Works correctly in pnpm desktop:dev (dev server on port 3080)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions