+12
-2
apps/api/src/xrpc/app/rocksky/song/matchSong.ts
+12
-2
apps/api/src/xrpc/app/rocksky/song/matchSong.ts
···
141
141
.from(tables.spotifyTokens)
142
142
.leftJoin(
143
143
tables.spotifyApps,
144
-
eq(tables.spotifyTokens.spotifyAppId, tables.spotifyApps.spotifyAppId),
144
+
eq(tables.spotifyApps.spotifyAppId, tables.spotifyTokens.spotifyAppId),
145
145
)
146
146
.leftJoin(
147
147
tables.spotifyAccounts,
148
-
eq(tables.spotifyAccounts.spotifyAppId, tables.spotifyApps.id),
148
+
eq(tables.spotifyAccounts.userId, tables.spotifyTokens.userId),
149
149
)
150
150
.where(eq(tables.spotifyAccounts.isBetaUser, true))
151
151
.limit(500)
152
152
.execute();
153
153
154
+
if (!spotifyTokens || spotifyTokens.length === 0) {
155
+
console.warn("No Spotify tokens available for beta users");
156
+
return undefined;
157
+
}
158
+
154
159
const { spotify_tokens, spotify_apps } =
155
160
spotifyTokens[Math.floor(Math.random() * spotifyTokens.length)];
161
+
162
+
if (!spotify_tokens || !spotify_apps) {
163
+
console.warn("Invalid Spotify token or app data");
164
+
return undefined;
165
+
}
156
166
157
167
const refreshToken = decrypt(
158
168
spotify_tokens.refreshToken,