35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
|
import { db } from "@/lib/db"
|
||
|
import { NextResponse } from "next/server";
|
||
|
import fetchUserWithImpersonation from '@/lib/fetch-user-impersonation';
|
||
|
import axios from "axios";
|
||
|
import { updateTwitchToken } from "@/data/twitch-reauthorize";
|
||
|
|
||
|
export async function GET(req: Request) {
|
||
|
try {
|
||
|
if (!process.env.TWITCH_BOT_CLIENT_ID)
|
||
|
return new NextResponse("Internal Error", { status: 500 });
|
||
|
|
||
|
const user = await fetchUserWithImpersonation(req)
|
||
|
if (!user) {
|
||
|
return new NextResponse("Unauthorized", { status: 401 });
|
||
|
}
|
||
|
|
||
|
const auth = await updateTwitchToken(user.id)
|
||
|
if (!auth)
|
||
|
return new NextResponse("Bad Request", { status: 400 })
|
||
|
|
||
|
const redemptions = await axios.get("https://api.twitch.tv/helix/channel_points/custom_rewards?broadcaster_id=" + auth.broadcaster_id,
|
||
|
{
|
||
|
headers: {
|
||
|
"Client-Id": process.env.TWITCH_BOT_CLIENT_ID,
|
||
|
"Authorization": "Bearer " + auth.access_token
|
||
|
}
|
||
|
}
|
||
|
)
|
||
|
|
||
|
return NextResponse.json(redemptions.data);
|
||
|
} catch (error) {
|
||
|
console.log("[REDEMPTIONS/ACTIONS]", error);
|
||
|
return new NextResponse("Internal Error", { status: 500 });
|
||
|
}
|
||
|
}
|