"use client"; import { Suspense, useState } from "react"; import { useSearchParams } from "next/navigation"; import { useTranslations } from "next-intl"; import { Link, useRouter } from "@/i18n/navigation"; import { createClient } from "@/lib/supabase/client"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { MessageSquare, UsersRound } from "lucide-react"; // `useSearchParams` opts the component out of static prerendering // unless it sits under a Suspense boundary. We split the form into // a child component so the outer page can prerender the chrome // (background, card frame) while the form hydrates with the query // string on the client. export default function LoginPage() { return ( ); } function LoginPageInner() { const t = useTranslations("auth.login"); const searchParams = useSearchParams(); // Forwarded from `/join/` when the visitor already has an // account. After a successful sign-in we send them to the join // page to accept rather than to /dashboard. const inviteToken = searchParams.get("invite"); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); const router = useRouter(); const supabase = createClient(); const handleLogin = async (e: React.FormEvent) => { e.preventDefault(); setError(null); setLoading(true); const { error } = await supabase.auth.signInWithPassword({ email, password, }); if (error) { setError(error.message); setLoading(false); return; } if (inviteToken) { router.push(`/join/${encodeURIComponent(inviteToken)}`); } else { router.push("/dashboard"); } }; return (
{inviteToken ? ( ) : ( )}
{inviteToken ? t("titleInvite") : t("title")} {inviteToken ? t("subtitleInvite") : t("subtitle")}
{error && (
{error}
)}
setEmail(e.target.value)} required className="border-slate-700 bg-slate-800 text-white placeholder:text-slate-500 focus-visible:border-primary focus-visible:ring-primary/20" />
{t("forgotPassword")}
setPassword(e.target.value)} required className="border-slate-700 bg-slate-800 text-white placeholder:text-slate-500 focus-visible:border-primary focus-visible:ring-primary/20" />

{t("noAccount")}{" "} {t("createAccount")}

); }