hermes-web/app/api/token/bot/route.ts

33 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-12-30 05:56:40 -05:00
import { db } from "@/lib/db"
2024-01-04 16:57:32 -05:00
import fetchUserWithImpersonation from "@/lib/fetch-user-impersonation";
2023-12-30 05:56:40 -05:00
import { NextResponse } from "next/server";
export async function GET(req: Request) {
try {
2024-01-04 16:57:32 -05:00
const user = await fetchUserWithImpersonation(req);
2023-12-30 05:56:40 -05:00
if (!user) {
2024-08-25 17:35:46 -04:00
return NextResponse.json({ message: 'Unauthorized.', error: null, value: null }, { status: 401 });
2023-12-30 05:56:40 -05:00
}
const api = await db.twitchConnection.findFirst({
where: {
userId: user.id
}
})
if (!api) {
2024-08-25 17:35:46 -04:00
return NextResponse.json({ message: 'You do not have permission for this.', error: null, value: null }, { status: 403 })
2023-12-30 05:56:40 -05:00
}
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);
2024-08-25 17:35:46 -04:00
return NextResponse.json({ message: 'Something went wrong', error: error, value: null }, { status: 500 })
2023-12-30 05:56:40 -05:00
}
}