accesscodes/src/app/api/xbox/profile/route.ts
2025-12-19 15:29:38 +00:00

37 lines
990 B
TypeScript

import { NextRequest, NextResponse } from "next/server";
import { getXboxProfileWithAvatar } from "@/lib/xbox";
export async function GET(req: NextRequest) {
try {
const { searchParams } = new URL(req.url);
const gamertag = searchParams.get("gamertag");
if (!gamertag) {
return NextResponse.json(
{ error: "Gamertag parameter is required" },
{ status: 400 }
);
}
// Use the modified function that reads from environment variables
const result = await getXboxProfileWithAvatar(gamertag);
return NextResponse.json(result);
} catch (error) {
console.error("Failed to fetch Xbox profile:", error);
// Return fallback data on error
const { searchParams } = new URL(req.url);
const gamertag = searchParams.get("gamertag") || "Unknown";
return NextResponse.json(
{
gamertag,
avatarUrl: "",
error: "Failed to fetch profile data"
},
{ status: 500 }
);
}
}