"use client"; /** * AuthModal — login + signup tabs in a portal-rendered dialog. * * The two forms share the existing LoginForm / SignUpForm widgets, so the * behaviour is identical to the standalone /login and /signup pages. * * The forms call `onSuccess` after they finish, but the modal does NOT close * from that callback — AuthGate's effect on `user` change handles the close * + promise resolution. This lets a single source of truth (AuthProvider's * user state) drive the whole flow. * * No router pushes here — the user's URL stays exactly where it was. */ import { useState, useEffect } from "react"; import { createPortal } from "react-dom"; import Link from "next/link"; import { X } from "lucide-react"; import { cn } from "@/lib/utils"; import { LoginForm } from "./login-form"; import { SignUpForm } from "./signup-form"; type Mode = "login" | "signup"; export function AuthModal({ onDismiss }: { onDismiss: () => void }) { const [mode, setMode] = useState("login"); // Esc-to-close — matches the pattern used elsewhere (reading settings, // search overlay) so the keyboard behavior feels consistent. useEffect(() => { function onKey(e: KeyboardEvent) { if (e.key === "Escape") onDismiss(); } document.addEventListener("keydown", onKey); return () => document.removeEventListener("keydown", onKey); }, [onDismiss]); // Lock scroll on the body while the modal is open. useEffect(() => { const prev = document.body.style.overflow; document.body.style.overflow = "hidden"; return () => { document.body.style.overflow = prev; }; }, []); if (typeof document === "undefined") return null; return createPortal( <>

{mode === "login" ? "Welcome back" : "Create your account"}

{/* Tab toggle */}
setMode("login")}> Log in setMode("signup")} > Sign up
{mode === "login" ? ( {}} forgotPasswordHref="/forgot-password" /> ) : ( {}} /> )}
{mode === "login" ? ( <> Need to reset your password?{" "} Click here . ) : ( <> By signing up you agree to our acceptable-use policy. Posts on your feed are public. )}
, document.body, ); } function ModeTab({ active, onClick, children, }: { active: boolean; onClick: () => void; children: React.ReactNode; }) { return ( ); }