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
- Open KnotCode desktop app (production
.dmg build)
- Go to Settings → Plugins → Spotify
- Click "Connect Spotify"
- Authenticate on Spotify's page
- 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
- 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
- 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
- Spotify Device Flow: If available, use device code flow instead of PKCE redirect (avoids the redirect problem entirely)
Affected Files
lib/spotify-auth.ts — getRedirectUri(), 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)
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, thegetRedirectUri()function returnshttp://127.0.0.1:3080/for Tauri builds: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
.dmgbuild)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
knotcode://spotify/callback) with Tauri, set it as the Spotify redirect URI, and handle the callback in the appgh auth loginworksAffected Files
lib/spotify-auth.ts—getRedirectUri(),startSpotifyLogin(),handleSpotifyCallback()src-tauri/tauri.conf.json— may need deep link plugin configEnvironment
pnpm desktop:dev(dev server on port 3080)