Added redemptions & redeemable actions. Fixed a few bugs.
This commit is contained in:
35
app/api/account/redemptions/route.ts
Normal file
35
app/api/account/redemptions/route.ts
Normal file
@ -0,0 +1,35 @@
|
||||
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 });
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user