import type { Metadata } from "next"; import { redirect } from "next/navigation"; import { desc, eq } from "drizzle-orm"; import { getSession } from "@/lib/session"; import { db } from "@/db"; import { contactMessages, imageConsents, membershipRequests, promotions } from "@/db/schema"; import { ImageConsentForm } from "@/components/ImageConsentForm"; import { isStaff } from "@/lib/rbac"; import { saveImageConsent } from "./actions"; import { BackendShell } from "./BackendShell"; import { NOINDEX } from "@/lib/seo"; export const dynamic = "force-dynamic"; // Espace privé : jamais indexé, même si une page fuyait hors du middleware. export const metadata: Metadata = { title: "Espace adhérent", robots: NOINDEX, }; export default async function BackendLayout({ children, }: { children: React.ReactNode; }) { const session = await getSession(); if (!session?.user) { redirect("/login"); } if ( session.user.role === "member" && session.user.memberId && !session.user.mustChangePassword ) { const latestConsent = await db .select({ id: imageConsents.id }) .from(imageConsents) .where(eq(imageConsents.memberId, session.user.memberId)) .orderBy(desc(imageConsents.createdAt)) .limit(1); if (latestConsent.length === 0) { return (
{/* eslint-disable-next-line @next/next/no-img-element */} Plein R
Consentement RGPD
Droit à l'image - première connexion adhérent

Votre choix sur le droit à l'image

Avant d'accéder à votre espace, indiquez si Plein R peut utiliser votre image dans les supports liés aux rencontres et à la vie de l'association.

); } } let pendingCount = 0; let inboxCount = 0; if (isStaff(session.user.role)) { const [pendingRows, newReqs, newMsgs] = await Promise.all([ db.select({ id: promotions.id }).from(promotions).where(eq(promotions.status, "pending")), db.select({ id: membershipRequests.id }).from(membershipRequests).where(eq(membershipRequests.status, "new")), db.select({ id: contactMessages.id }).from(contactMessages).where(eq(contactMessages.status, "new")), ]); pendingCount = pendingRows.length; inboxCount = newReqs.length + newMsgs.length; } return ( {children} ); }