Skip to content

Commit efda330

Browse files
committed
move cache update for token into separate method
1 parent b968704 commit efda330

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/lib/core/fetch.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ const refreshAccessToken = async (): Promise<boolean> => {
4545
throw new Error('Could not refresh authorization token')
4646
}
4747

48-
redisClient.set(
49-
`spotify_${process.env.TWITCH_ID}`,
50-
JSON.stringify(data),
51-
)
5248
accessToken = data
5349
refreshToken = data.refresh_token || null
5450
// setTokens(data.accessToken, data.refreshToken)
@@ -70,6 +66,18 @@ const refreshAccessToken = async (): Promise<boolean> => {
7066
}
7167
}
7268

69+
// const setTokens = async (newToken: SpotifyAccessToken, newRefreshToken: string) => {
70+
// redisClient.set(
71+
// `spotify_${process.env.TWITCH_ID}`,
72+
// JSON.stringify(newToken),
73+
// )
74+
75+
// accessToken = newToken
76+
// refreshToken = newRefreshToken
77+
78+
79+
// }
80+
7381
const getSpotifyToken = async (): Promise<SpotifyAccessToken | null> => {
7482
const twitchId = process.env.TWITCH_ID || '89181064'
7583
const spotifyAccessToken = await redisClient.get(`spotify_${twitchId}`)
@@ -108,7 +116,7 @@ export const authFetch = async (
108116
}
109117

110118
if (accessToken && options.headers) {
111-
;(options.headers as Record<string, string>)['Authorization'] =
119+
; (options.headers as Record<string, string>)['Authorization'] =
112120
`Bearer ${accessToken.access_token}`
113121
}
114122

@@ -123,7 +131,7 @@ export const authFetch = async (
123131
if (refreshed) {
124132
// Retry the original request with the new token
125133
if (options.headers) {
126-
;(options.headers as Record<string, string>)['Authorization'] =
134+
; (options.headers as Record<string, string>)['Authorization'] =
127135
`Bearer ${accessToken.access_token}`
128136
}
129137
response = await fetch(url, options)

0 commit comments

Comments
 (0)