ClauseGuard / web /app /api /history /route.ts
gaurv007's picture
v3: All missing features — auth callback, settings, PDF export, email (Resend), JWT auth, /api/history, SaulLM integration, extension icons, Supabase 0.10 breaking changes, Stripe v22
e3f2df1 verified
raw
history blame contribute delete
977 Bytes
import { NextRequest, NextResponse } from "next/server";
import { createClient } from "@/lib/supabase/server";
export async function GET(req: NextRequest) {
const supabase = await createClient();
const { data: { user } } = await supabase.auth.getUser();
if (!user) {
return NextResponse.json({ error: "Not authenticated" }, { status: 401 });
}
const url = new URL(req.url);
const limit = Math.min(parseInt(url.searchParams.get("limit") || "20"), 100);
const offset = parseInt(url.searchParams.get("offset") || "0");
const { data: analyses, count, error } = await supabase
.from("analyses")
.select("*", { count: "exact" })
.eq("user_id", user.id)
.order("created_at", { ascending: false })
.range(offset, offset + limit - 1);
if (error) {
return NextResponse.json({ error: error.message }, { status: 500 });
}
return NextResponse.json({
analyses: analyses || [],
total: count || 0,
limit,
offset,
});
}