(discord) fix eagerly refreshing access token

This commit is contained in:
Valentyne Stigloher 2024-06-16 21:34:21 +02:00
parent ccba73890f
commit 5ee23fb01d

View File

@ -62,7 +62,7 @@ const getAccessToken = async (userId: string) => {
if (tokenSet === undefined) {
return undefined;
}
if (Date.now() > tokenSet.expires_in) {
if (Date.now() > tokenSet.expires_at!) {
const token: TokenSet = await fetch(`${BASE_DISCORD_URI}/oauth2/token`, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
@ -74,6 +74,7 @@ const getAccessToken = async (userId: string) => {
}).then((res) => res.json());
token.expires_at = Date.now() + tokenSet.expires_in * 1e3;
store.set(userId, token);
return token.access_token;
}
return tokenSet.access_token;
};