Skip to content
This repository was archived by the owner on Mar 2, 2025. It is now read-only.

Commit 2de4935

Browse files
committed
some additional checks for discord token
1 parent 578d45d commit 2de4935

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

utilities/discordhelper.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,26 @@ const checkTokenValid = async (userid, force = false) => {
105105
if (!userObj)
106106
return false;
107107

108+
const res = await fetch(`${discordEndPoint}/oauth2/@me`, {
109+
method: 'GET',
110+
headers: {
111+
'Authorization': `Bearer ${userObj.access_token}`,
112+
}
113+
});
114+
115+
if (res.status !== 200) {
116+
logger.info("Refreshing expired token, expire time got by request...");
117+
return await refreshToken(userObj);
118+
}
119+
108120
const lastRefreshedTime = new Date(userObj.last_refreshed_time);
109121
const now = new Date();
110122
const timeDifference = now - lastRefreshedTime;
111123

112124
if (timeDifference < 7 * 24 * 60 * 60 * 1000 && !force)
113125
return true;
114126

127+
logger.info("Refreshing expired token, expire time got by timeDiff...");
115128
return await refreshToken(userObj);
116129
}
117130

0 commit comments

Comments
 (0)