"use client"; import { motion } from "framer-motion"; import { ReactNode } from "react"; import { useAuth } from "@/context/AuthContext"; import { useState } from "react"; import { Input } from "./Input"; import Button from "./Button"; interface AuthGateProps { children: ReactNode; title?: string; } export default function AuthGate({ children, title = "ECHO" }: AuthGateProps) { const { user, isLoading, error, login, register, clearError } = useAuth(); const [usernameInput, setUsernameInput] = useState(""); const [passwordInput, setPasswordInput] = useState(""); const [isRegisterMode, setIsRegisterMode] = useState(false); const [statusMsg, setStatusMsg] = useState(""); if (isLoading) { return (
E
Initializing ECHO
); } if (!user) { const handleSubmit = async () => { if (!usernameInput.trim() || !passwordInput.trim()) return; clearError(); setStatusMsg(""); try { if (isRegisterMode) { await register(usernameInput, passwordInput); setStatusMsg("Account created."); } else { await login(usernameInput, passwordInput); setStatusMsg("Welcome back."); } setPasswordInput(""); } catch { // error is set by context } }; return (
{/* Logo Mark */}
E

{title}

Emotional Chronicle · Helping Observations

{/* Form */}
setUsernameInput(e.target.value)} placeholder="your handle" /> setPasswordInput(e.target.value)} placeholder="••••••••" onKeyDown={(e) => { if (e.key === "Enter") void handleSubmit(); }} />
{/* Feedback */} {statusMsg && ( ✓ {statusMsg} )} {error && ( ⚠ {error} )} {/* Decorative bottom line */}
Powered by Emily AI
); } return <>{children}; }