feat(home): add Ver lista do Martin CTA, mints anonymous visitor guest
Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled
Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled
This commit is contained in:
12
app/api/public/visit/route.ts
Normal file
12
app/api/public/visit/route.ts
Normal file
@@ -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 });
|
||||||
|
}
|
||||||
13
app/page.tsx
13
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 (
|
return (
|
||||||
<div className="min-h-screen flex items-center justify-center text-center px-6">
|
<div className="min-h-screen flex items-center justify-center text-center px-6">
|
||||||
<div className="max-w-xl">
|
<div className="max-w-xl">
|
||||||
<h1 className="text-4xl font-bold mb-3">Lista de Presentes</h1>
|
<h1 className="text-4xl font-bold mb-3">Lista de Presentes</h1>
|
||||||
<p className="text-lg text-gray-500">
|
<p className="text-lg text-gray-500 mb-6">
|
||||||
Gerencie listas de presentes e convites com facilidade.
|
Gerencie listas de presentes e convites com facilidade.
|
||||||
</p>
|
</p>
|
||||||
|
<button
|
||||||
|
onClick={onVisit}
|
||||||
|
className="inline-flex items-center px-5 py-3 rounded-md bg-indigo-600 text-white font-medium hover:bg-indigo-700 transition cursor-pointer"
|
||||||
|
>
|
||||||
|
Ver lista do Martin
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user