From 17117ed7b25ff34d75eb99e4394c7db1442566bb Mon Sep 17 00:00:00 2001 From: belisards Date: Sun, 3 May 2026 17:13:41 -0300 Subject: [PATCH] feat(home): add Ver lista do Martin CTA, mints anonymous visitor guest --- app/api/public/visit/route.ts | 12 ++++++++++++ app/page.tsx | 13 ++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 app/api/public/visit/route.ts diff --git a/app/api/public/visit/route.ts b/app/api/public/visit/route.ts new file mode 100644 index 0000000..1af4d96 --- /dev/null +++ b/app/api/public/visit/route.ts @@ -0,0 +1,12 @@ +import { NextRequest, NextResponse } from 'next/server'; +import { db, guests } from '@/lib/db'; +import { USR_COOKIE, buildCookie, isSecureCookie } from '@/lib/auth/cookies'; + +const ONE_YEAR = 60 * 60 * 24 * 365; + +export async function POST(request: NextRequest) { + const [row] = await db.insert(guests).values({ name: 'Visitante' }).returning(); + const headers = new Headers(); + headers.append('Set-Cookie', buildCookie(USR_COOKIE, row.id, isSecureCookie(request), ONE_YEAR)); + return NextResponse.json({ success: true, guestId: row.id }, { headers }); +} diff --git a/app/page.tsx b/app/page.tsx index dd65557..9bc2d96 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -83,13 +83,24 @@ export default function HomePage() { ); } + const onVisit = async () => { + await fetch('/api/public/visit', { method: 'POST', credentials: 'include' }); + router.replace('/'); + }; + return (

Lista de Presentes

-

+

Gerencie listas de presentes e convites com facilidade.

+
);