Skip to content

Commit

Permalink
fix spotify weird refresh_token behaviour (I hope)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luna-devv committed Jan 4, 2024
1 parent 3b56649 commit 9409609
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "lunify.js",
"description": "A basic api wrapper for the spotify api covering the oauth routes.",
"version": "0.1.6",
"version": "0.1.7",
"main": "dist/src/lib/index.js",
"types": "dist/src/lib/index.d.js",
"files": [
Expand Down
10 changes: 9 additions & 1 deletion src/lib/managers/oauth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export class OauthManager extends EventEmitter {
},
body: params
});
res.created_timestamp = Date.now();

res.created_timestamp = Date.now();
return new UserOauth(this.client, res);
}

Expand All @@ -72,6 +72,14 @@ export class OauthManager extends EventEmitter {
throw Error(res.message as string);
}

// Sometimes, <UserOauth>.refreshToken is null for some reason.
// Spotify claims they return a new refresh token, but I don't trust them.
// I am just testing things and see what sticks, will be removed if this doesn't fix it.
// It only happens sometimes, it seems to only appear after a few days without restarting the node process.
// Contact me: luna@waya.one - https://discord.gg/yYd6YKHQZH
// https://developer.spotify.com/documentation/web-api/tutorials/refreshing-tokens
res.refresh_token ||= refreshToken;

res.created_timestamp = Date.now();
return new UserOauth(this.client, res);
}
Expand Down

0 comments on commit 9409609

Please sign in to comment.