Spaces:
Running
Running
import { NextResponse } from "next/server"; | |
import { getChats } from "@/lib/chat-store"; | |
export async function GET(request: Request) { | |
try { | |
const userId = request.headers.get('x-user-id'); | |
if (!userId) { | |
return NextResponse.json({ error: "User ID is required" }, { status: 400 }); | |
} | |
const chats = await getChats(userId); | |
return NextResponse.json(chats); | |
} catch (error) { | |
console.error("Error fetching chats:", error); | |
return NextResponse.json( | |
{ error: "Failed to fetch chats" }, | |
{ status: 500 } | |
); | |
} | |
} |