32 lines
913 B
TypeScript
32 lines
913 B
TypeScript
import { db } from "@/lib/db"
|
|
import { NextResponse } from "next/server";
|
|
import fetchUserUsingAPI from "@/lib/validate-api";
|
|
|
|
export async function GET(req: Request) {
|
|
try {
|
|
const user = await fetchUserUsingAPI(req)
|
|
if (!user) {
|
|
return new NextResponse("Unauthorized", { status: 401 });
|
|
}
|
|
|
|
const { searchParams } = new URL(req.url)
|
|
let userId = searchParams.get('id')
|
|
|
|
if (userId == null) {
|
|
if (user != null) {
|
|
userId = user.id as string;
|
|
}
|
|
}
|
|
|
|
const connection = await db.twitchConnection.findFirst({
|
|
where: {
|
|
userId: userId as string
|
|
}
|
|
});
|
|
|
|
return NextResponse.json(connection);
|
|
} catch (error) {
|
|
console.log("[CONNECTION/TWITCH]", error);
|
|
return new NextResponse("Internal Error", { status: 500 });
|
|
}
|
|
} |