Skip to content

Commit 83563fc

Browse files
committed
fix: use 127.0.0.1 for Spotify redirect URI (localhost rejected by Spotify)
1 parent 2d74df7 commit 83563fc

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

lib/spotify-auth.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,17 @@ async function generateCodeChallenge(verifier: string): Promise<string> {
7575
}
7676

7777
function getRedirectUri(): string {
78+
// Spotify requires http://127.0.0.1 for loopback redirects (rejects http://localhost)
79+
// Always use 127.0.0.1 with the current port for Tauri/local builds
7880
const origin = window.location.origin
79-
// In production Tauri, app is served via localhost plugin on http://localhost:3080
80-
// Use the actual origin so the redirect URI matches what Spotify redirects back to
81-
if (origin.startsWith('tauri://')) {
82-
// Fallback if localhost plugin isn't active (shouldn't happen)
83-
return 'http://localhost:3080/'
81+
if (
82+
origin.startsWith('tauri://') ||
83+
origin.includes('localhost') ||
84+
origin.includes('127.0.0.1')
85+
) {
86+
const port = window.location.port || '3080'
87+
return `http://127.0.0.1:${port}/`
8488
}
85-
// Use origin directly — works for localhost:3080 (Tauri prod), localhost:3000 (dev), or deployed URL
8689
return origin + '/'
8790
}
8891

0 commit comments

Comments
 (0)