Progress so far
This commit is contained in:
34
app/api/token/bot/route.ts
Normal file
34
app/api/token/bot/route.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { db } from "@/lib/db"
|
||||
import fetchUserUsingAPI from "@/lib/validate-api";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(req: Request) {
|
||||
try {
|
||||
const user = await fetchUserUsingAPI(req);
|
||||
if (!user) {
|
||||
return new NextResponse("Unauthorized", { status: 401 });
|
||||
}
|
||||
|
||||
const api = await db.twitchConnection.findFirst({
|
||||
where: {
|
||||
userId: user.id
|
||||
}
|
||||
})
|
||||
|
||||
if (!api) {
|
||||
return new NextResponse("Forbidden", { status: 403 });
|
||||
}
|
||||
|
||||
const data = {
|
||||
client_id: process.env.TWITCH_BOT_CLIENT_ID,
|
||||
client_secret: process.env.TWITCH_BOT_CLIENT_SECRET,
|
||||
access_token: api.accessToken,
|
||||
refresh_token: api.refreshToken,
|
||||
broadcaster_id: api.broadcasterId
|
||||
}
|
||||
return NextResponse.json(data);
|
||||
} catch (error) {
|
||||
console.log("[TOKENS/GET]", error);
|
||||
return new NextResponse("Internal Error", { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user