- Delete: CookieConsent.astro (old Astro component) - Delete: consent.ts, right-to-be-forgotten.ts (Astro API routes) - Update: route.ts is now proper Next.js route handler - Update: sitemap-template.md - replace Astro pages structure with Next.js app/ structure - Update: payload-nextjs-notes.md - fix MongoDB port reference - Note: seo-multi-channel auto_publish.py is for Astro sites (kept as-is)
PDPA Consent Logging Template
Template สำหรับเพิ่ม PDPA consent logging ใน Next.js + Payload CMS (MongoDB)
Files
consent/
├── collections/
│ └── ConsentLogs.ts # Payload collection สำหรับ consent logs
├── api/
│ └── route.ts # API endpoint สำหรับบันทึก consent
├── cookie-banner.tsx # CookieBanner component
└── README.md
วิธีใช้
1. เพิ่ม ConsentLogs Collection
Copy collections/ConsentLogs.ts ไปที่ src/collections/ ของ project
2. สร้าง API Endpoint
Copy api/route.ts ไปที่ src/app/api/consent/route.ts
3. เพิ่ม CookieBanner Component
Copy cookie-banner.tsx ไปที่ src/components/
4. เพิ่มใน Layout
เพิ่ม <CookieBanner /> ใน src/app/(frontend)/layout.tsx:
import { CookieBanner } from '@/components/cookie-banner'
export default function RootLayout({ children }) {
return (
<html>
<body>
{children}
<CookieBanner />
</body>
</html>
)
}
5. เพิ่ม Collection ใน payload.config.ts
import ConsentLogs from './collections/ConsentLogs'
export default buildConfig({
collections: [Users, Media, Snacks, Orders, ConsentLogs],
// ...
})
API
POST /api/consent
บันทึก consent action
Request:
{
"action": "accept",
"purpose": "all",
"analytics": true,
"marketing": false,
"functional": true
}
Response:
{
"success": true,
"doc": {
"id": "...",
"action": "accept",
"purpose": "all",
"analytics": true,
"marketing": false,
"functional": true,
"userAgent": "Mozilla/5.0...",
"ip": "127.0.0.1",
"timestamp": "2026-04-10T00:00:00.000Z"
}
}
⚠️ Pitfalls สำคัญ
- ใช้
mongooseAdapterไม่ใช่mongodbAdapter - ConsentLogs ต้องใช้
export defaultไม่ใช่ named export