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 (