A decentralized music tracking and discovery platform built on AT Protocol 🎵

fix: refactor Spotify token retrieval to use correct account properties and improve error handling

+8 -17
+8 -17
apps/api/src/spotify/app.ts
··· 114 114 eq(spotifyAccounts.isBetaUser, true) 115 115 ) 116 116 ) 117 - .limit(1) 118 - .then((rows) => rows[0]); 119 - 120 - const spotifyAppId = spotifyAccount.spotifyAppId 121 - ? spotifyAccount.spotifyAppId 122 - : env.SPOTIFY_CLIENT_ID; 123 - 124 - const spotifyAppToken = await ctx.db 125 - .select() 126 - .from(spotifyTokens) 127 117 .leftJoin( 128 118 spotifyApps, 129 119 eq(spotifyTokens.spotifyAppId, spotifyApps.spotifyAppId) 130 120 ) 131 - .where(eq(spotifyTokens.spotifyAppId, spotifyAppId)) 132 121 .limit(1) 133 122 .then((rows) => rows[0]); 134 123 124 + const spotifyAppId = spotifyAccount.spotify_accounts.spotifyAppId 125 + ? spotifyAccount.spotify_accounts.spotifyAppId 126 + : env.SPOTIFY_CLIENT_ID; 127 + const spotifySecret = spotifyAccount.spotify_apps.spotifySecret 128 + ? spotifyAccount.spotify_apps.spotifySecret 129 + : env.SPOTIFY_CLIENT_SECRET; 130 + 135 131 const response = await fetch("https://accounts.spotify.com/api/token", { 136 132 method: "POST", 137 133 headers: { ··· 142 138 code, 143 139 redirect_uri: env.SPOTIFY_REDIRECT_URI, 144 140 client_id: spotifyAppId, 145 - client_secret: spotifyAppToken?.spotify_apps 146 - ? decrypt( 147 - spotifyAppToken.spotify_apps.spotifySecret, 148 - env.SPOTIFY_ENCRYPTION_KEY 149 - ) 150 - : env.SPOTIFY_CLIENT_SECRET, 141 + client_secret: decrypt(spotifySecret, env.SPOTIFY_ENCRYPTION_KEY), 151 142 }), 152 143 }); 153 144 const {