- Add authentication with NextAuth v5 (credentials + email verification) - Implement dashboard with glycemia tracking and AI analysis - Add PDF report generation for Premium users - Implement Stripe integration for Premium subscriptions - Add responsive UI with Tailwind CSS and shadcn components - Database schema with Prisma ORM and PostgreSQL support - Real-time glycemia visualization with Recharts - Mobile-optimized entry form - User profile management with medical information - Subscription lifecycle management (create, cancel, webhook) - Email notifications with Resend - Feature gates for Free vs Premium plans Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import { redirect } from "next/navigation";
|
|
import { auth } from "@/lib/auth";
|
|
import { prisma } from "@/lib/prisma";
|
|
import { HistoryClient } from "@/app/historique/HistoryClient";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
export const metadata = { title: "Historique — Diabetix" };
|
|
|
|
export default async function HistoriquePage() {
|
|
const session = await auth();
|
|
if (!session?.user?.id) redirect("/auth/login");
|
|
const userId = session.user.id;
|
|
|
|
const plan = (session.user as { plan?: string }).plan ?? "FREE";
|
|
const cutoff = plan === "PREMIUM"
|
|
? undefined
|
|
: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000);
|
|
|
|
const readings = await prisma.reading.findMany({
|
|
where: { userId, ...(cutoff ? { measuredAt: { gte: cutoff } } : {}) },
|
|
orderBy: { measuredAt: "desc" },
|
|
});
|
|
|
|
return (
|
|
<HistoryClient
|
|
readings={readings.map((r) => ({
|
|
id: r.id,
|
|
measuredAt: r.measuredAt.toISOString(),
|
|
moment: r.moment,
|
|
value: r.value,
|
|
notes: r.notes,
|
|
}))}
|
|
isPremium={plan === "PREMIUM"}
|
|
/>
|
|
);
|
|
}
|