From 8d9e7c07093eae0ed196368a7ac389da40973975 Mon Sep 17 00:00:00 2001 From: belisards Date: Sun, 3 May 2026 16:31:40 -0300 Subject: [PATCH] =?UTF-8?q?feat(home):=20show=20convite=20necess=C3=A1rio;?= =?UTF-8?q?=20route=20admin/guest=20tokens?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/page.tsx | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/app/page.tsx b/app/page.tsx index 269930f..ad5e007 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,6 +1,63 @@ 'use client'; -export default function Home() { +import { useEffect, useState } from 'react'; +import { useRouter, useSearchParams } from 'next/navigation'; +import { authApi } from '@/lib/api'; + +export default function HomePage() { + const router = useRouter(); + const params = useSearchParams(); + const [state, setState] = useState<'checking' | 'guest' | 'none'>('checking'); + const [guestName, setGuestName] = useState(''); + + useEffect(() => { + let cancelled = false; + (async () => { + const adm = params.get('adm'); + const usr = params.get('usr'); + try { + if (adm) { + await authApi.session({ adm }); + router.replace('/admin'); + return; + } + if (usr) { + await authApi.session({ usr }); + } + const who = await authApi.whoami(); + if (cancelled) return; + if (who.role === 'admin') { + router.replace('/admin'); + return; + } + if (who.role === 'guest') { + setGuestName(who.guest.name); + setState('guest'); + return; + } + setState('none'); + } catch { + if (!cancelled) setState('none'); + } + })(); + return () => { cancelled = true; }; + }, [params, router]); + + if (state === 'checking') { + return
Carregando…
; + } + + if (state === 'guest') { + return ( +
+
+

Olá, {guestName}!

+

Visite o link da lista que você recebeu.

+
+
+ ); + } + return (