From eb35a62523501064f828c28d519943e12d158873 Mon Sep 17 00:00:00 2001 From: John Costa Date: Mon, 30 Jun 2025 18:59:23 +0100 Subject: [PATCH] fix --- src/lib/twitch.ts | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/lib/twitch.ts b/src/lib/twitch.ts index 895c292..7ab63d6 100644 --- a/src/lib/twitch.ts +++ b/src/lib/twitch.ts @@ -42,15 +42,24 @@ export const twitchFollowEvent = z.object({ // Webhook -> Redeem of channel reward export const createTwitchClient = () => { const getAccessToken = async () => { - const twitchAuthResponse = await fetch( - `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`, - { - method: "POST", - headers: { - "Content-Type": "application/x-www-form-urlencoded", + const authUrl = `https://id.twitch.tv/oauth2/authorize` + + `?response_type=code` + + `&client_id=${TWITCH_APP_CLIENT_ID}` + + `&redirect_uri=${encodeURIComponent("https://twitch.johncosta.tech/redirect")}` + + `&scope=moderator:read:followers` + + + const twitchAuthResponse = + await fetch( + authUrl, + { + method: "POST", + headers: { + "Content-Type": "application/x-www-form-urlencoded", + }, }, - }, - ); + ); + const { access_token } = authBodyValidator.parse( await twitchAuthResponse.json(),