This commit is contained in:
2025-06-30 19:21:58 +01:00
parent 3daef70f1b
commit c4981f5ffa

View File

@ -1,4 +1,3 @@
import { building } from "$app/environment";
import { HASH_SECRET, TWITCH_APP_CLIENT_ID, TWITCH_APP_SECRET } from "$env/static/private";
import { z } from "zod";
@ -43,21 +42,9 @@ export const twitchFollowEvent = z.object({
// Webhook -> Redeem of channel reward
export const createTwitchClient = () => {
const getAccessToken = async () => {
if (building) {
return '';
}
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` +
`&state=mkldsamkldsamkldsamkldsa`
const twitchAuthResponse =
await fetch(
authUrl,
`https://id.twitch.tv/oauth2/token?client_id=${TWITCH_APP_CLIENT_ID}&client_secret=${TWITCH_APP_SECRET}&grant_type=client_credentials`, // No 'scope' here!
{
method: "POST",
headers: {
@ -67,10 +54,10 @@ export const createTwitchClient = () => {
);
const json = await twitchAuthResponse.json();
console.log(json);
const body = await twitchAuthResponse.json();
console.log(body);
const { access_token } = authBodyValidator.parse(
json,
body
);
return access_token;
@ -105,8 +92,7 @@ export const createTwitchClient = () => {
);
const res = await twitchSubResponse.json();
console.log(res);
console.log("Subscribe to follow: ", res);
};
return {