This commit is contained in:
2025-06-30 18:59:23 +01:00
parent e868153bbb
commit eb35a62523

View File

@ -42,15 +42,24 @@ export const twitchFollowEvent = z.object({
// Webhook -> Redeem of channel reward // Webhook -> Redeem of channel reward
export const createTwitchClient = () => { export const createTwitchClient = () => {
const getAccessToken = async () => { const getAccessToken = async () => {
const twitchAuthResponse = await fetch( const authUrl = `https://id.twitch.tv/oauth2/authorize` +
`https://id.twitch.tv/oauth2/token?client_id=${TWITCH_APP_CLIENT_ID}&client_secret=${TWITCH_APP_SECRET}&grant_type=client_credentials&&redirect_uri=https://twitch.johncosta.tech/redirect&scope=moderator:read:followers`, `?response_type=code` +
{ `&client_id=${TWITCH_APP_CLIENT_ID}` +
method: "POST", `&redirect_uri=${encodeURIComponent("https://twitch.johncosta.tech/redirect")}` +
headers: { `&scope=moderator:read:followers`
"Content-Type": "application/x-www-form-urlencoded",
const twitchAuthResponse =
await fetch(
authUrl,
{
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
}, },
}, );
);
const { access_token } = authBodyValidator.parse( const { access_token } = authBodyValidator.parse(
await twitchAuthResponse.json(), await twitchAuthResponse.json(),