fix
This commit is contained in:
@ -1,4 +1,3 @@
|
|||||||
import { building } from "$app/environment";
|
|
||||||
import { HASH_SECRET, TWITCH_APP_CLIENT_ID, TWITCH_APP_SECRET } from "$env/static/private";
|
import { HASH_SECRET, TWITCH_APP_CLIENT_ID, TWITCH_APP_SECRET } from "$env/static/private";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
@ -43,21 +42,9 @@ 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 () => {
|
||||||
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 =
|
const twitchAuthResponse =
|
||||||
await fetch(
|
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",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
@ -67,10 +54,10 @@ export const createTwitchClient = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
const json = await twitchAuthResponse.json();
|
const body = await twitchAuthResponse.json();
|
||||||
console.log(json);
|
console.log(body);
|
||||||
const { access_token } = authBodyValidator.parse(
|
const { access_token } = authBodyValidator.parse(
|
||||||
json,
|
body
|
||||||
);
|
);
|
||||||
|
|
||||||
return access_token;
|
return access_token;
|
||||||
@ -105,8 +92,7 @@ export const createTwitchClient = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const res = await twitchSubResponse.json();
|
const res = await twitchSubResponse.json();
|
||||||
|
console.log("Subscribe to follow: ", res);
|
||||||
console.log(res);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
Reference in New Issue
Block a user