22 lines
643 B
TypeScript
22 lines
643 B
TypeScript
import { NextResponse } from "next/server";
|
|
import { getAuthToken, medusaAuthFetch } from "@/lib/auth";
|
|
|
|
export async function GET() {
|
|
const token = await getAuthToken();
|
|
if (!token) {
|
|
return NextResponse.json({ error: "Not authenticated" }, { status: 401 });
|
|
}
|
|
|
|
try {
|
|
const data = await medusaAuthFetch<{ orders: unknown[] }>(
|
|
"/store/orders?order=-created_at&fields=*items,*items.variant",
|
|
);
|
|
return NextResponse.json(data);
|
|
} catch (e) {
|
|
console.error("[account:orders]", (e as Error).message);
|
|
return NextResponse.json(
|
|
{ error: "Failed to fetch orders" },
|
|
{ status: 500 },
|
|
);
|
|
}
|
|
}
|