I AM RETARDED
This commit is contained in:
parent
7021328618
commit
9d674ea262
1 changed files with 8 additions and 4 deletions
|
@ -5,25 +5,29 @@ export async function reqSpotify(
|
|||
method: string = "GET",
|
||||
data?: object
|
||||
) {
|
||||
if (state.explodesAt >= Date.now()) {
|
||||
if (state.explodesAt <= Date.now()) {
|
||||
console.log("We will be refreshing the token");
|
||||
const tokenRes = await (
|
||||
await fetch("https://accounts.spotify.com/api/token", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
Authorization: `Basic ${Buffer.from(
|
||||
process.env.CLIENT_ID + ":" + process.env.CLIENT_SECRET
|
||||
).toString("base64")}`
|
||||
},
|
||||
body: new URLSearchParams({
|
||||
refresh_token: state.refreshToken,
|
||||
client_id: process.env.CLIENT_ID!,
|
||||
grant_type: "refresh_token"
|
||||
})
|
||||
})
|
||||
).json();
|
||||
console.log(tokenRes);
|
||||
|
||||
if (!tokenRes.error) {
|
||||
state.accessToken = tokenRes.access_token;
|
||||
state.explodesAt = Date.now() + tokenRes.expires_in * 1000;
|
||||
state.refreshToken = tokenRes.refresh_token;
|
||||
state.refreshToken = tokenRes.refresh_token || state.refreshToken;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue