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 (
+
Gerencie listas de presentes e convites com facilidade.
+