28 lines
818 B
TypeScript
28 lines
818 B
TypeScript
import { auth } from "@/auth";
|
|
import { NextRequest, NextResponse } from "next/server";
|
|
import { getGuildRoles } from "@/lib/discord";
|
|
|
|
// GET - Fetch all roles for a guild
|
|
export async function GET(
|
|
request: NextRequest,
|
|
{ params }: { params: Promise<{ guildId: string }> }
|
|
) {
|
|
const session = await auth();
|
|
const { guildId } = await params;
|
|
|
|
if (!session?.accessToken) {
|
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
}
|
|
|
|
try {
|
|
const roles = await getGuildRoles(guildId, session.accessToken as string);
|
|
return NextResponse.json(roles);
|
|
} catch (error) {
|
|
console.error("Error fetching roles:", error);
|
|
return NextResponse.json(
|
|
{ error: "Internal server error" },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|