Skip to content

Commit

Permalink
Properly handle oauth tokens that have an expiry time of zero.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravendwyr committed Sep 22, 2024
1 parent 5e9fe08 commit 0bfa63f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion tpp-botcheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ function validateToken(first) {
})
.then(data => {
if (data.login && first) {
printMessage(`OAuth token is valid and will expire on ${new Date(Date.now() + (data.expires_in * 1000))}`)
if (data.expires_in > 0) printMessage(`OAuth token is valid and will expire on ${new Date(Date.now() + (data.expires_in * 1000))}`)
else printMessage(`OAuth token is valid and but Twitch did not provide an expiry date.`)

fetchFromTwitchInsights()
} else if (data.status == 401) {
printMessage(`OAuth token is invalid or has expired. Please create a new one and update env file.`)
Expand Down
6 changes: 4 additions & 2 deletions tpp-chatterdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ function validateToken(print) {
fetch(`https://id.twitch.tv/oauth2/validate`, { method: 'GET', headers: { 'Authorization': `OAuth ${process.env.TWITCH_OAUTH}` }})
.then(data => data.json())
.then(data => {
if (data.login && print) printMessage(`OAuth token is valid and will expire on ${new Date(Date.now() + (data.expires_in * 1000))}`)
else if (data.status == 401) {
if (data.login && print) {
if (data.expires_in > 0) printMessage(`OAuth token is valid and will expire on ${new Date(Date.now() + (data.expires_in * 1000))}`)
else printMessage(`OAuth token is valid and but Twitch did not provide an expiry date.`)
} else if (data.status == 401) {
printMessage(`OAuth token is invalid or has expired. Please create a new one and update env file.`)
setTimeout(process.exit, 1000)
}
Expand Down

0 comments on commit 0bfa63f

Please sign in to comment.