Skip to content

Commit

Permalink
fix(twitch): change to Bearer token
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed Mar 29, 2022
1 parent 5e0249f commit 316d596
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 14 additions & 5 deletions src/services/twitch/token/refresh.ts
Expand Up @@ -21,6 +21,11 @@ export function cleanErrors(type: keyof typeof errorCount) {
errorCount[type] = 0;
}

const errorSent = {
bot: false,
broadcaster: false,
};

const urls = {
'SogeBot Token Generator': 'https://twitch-token-generator.soge.workers.dev/refresh/',
};
Expand Down Expand Up @@ -52,13 +57,17 @@ export const refresh = async (type: 'bot' | 'broadcaster'): Promise<string | nul
}

if (errorCount[type] > 20) {
warning(`Limit of token refresh for ${type} reached, please change your tokens!`);
addUIError({
name: 'Token Error!',
message: `Limit of token refresh for ${type} reached, please change your tokens!`,
});
if (!errorSent[type]) {
warning(`Limit of token refresh for ${type} reached, please change your tokens!`);
addUIError({
name: 'Token Error!',
message: `Limit of token refresh for ${type} reached, please change your tokens!`,
});
}
errorSent[type] = true;
return null;
}
errorSent[type] = false;

debug('oauth.validate', 'Refreshing access token of ' + type);
const url = urls[tokenService];
Expand Down
2 changes: 1 addition & 1 deletion src/services/twitch/token/validate.ts
Expand Up @@ -101,7 +101,7 @@ export const validate = async (type: 'bot' | 'broadcaster', retry = 0): Promise
scopes: string[]
}>(url, {
headers: {
Authorization: 'OAuth ' + token,
Authorization: 'Bearer ' + token,
},
});
expirationDate[type] = Date.now() + request.data.expires_in * 1000;
Expand Down

0 comments on commit 316d596

Please sign in to comment.