import * as React from 'react'; import { Box, TextField, Button, Typography, IconButton, CircularProgress, Link } from '@mui/material'; import ArrowBackRoundedIcon from '@mui/icons-material/ArrowBackRounded'; export type AuthMode = "login" | "register"; export interface AuthPageProps { mode: AuthMode; onBack(): void; onSwitchMode(): void; login(username: string, password: string): Promise; register(username: string, password: string): Promise; loading: boolean; error: string | null; currentUser: any; } export function AuthPage({ mode, onBack, onSwitchMode, login, register, loading, error, currentUser, }: AuthPageProps) { const [username, setUsername] = React.useState(''); const [password, setPassword] = React.useState(''); const isLogin = mode === "login"; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (isLogin) { await login(username, password); } else { await register(username, password); } }; // ✅ Auto-return if already logged in React.useEffect(() => { if (currentUser) onBack(); }, [currentUser, onBack]); return ( {isLogin ? "Sign In" : "Create Account"} {isLogin ? "Please log in to continue" : "Create an account to get started"}
setUsername(e.target.value)} required autoFocus /> setPassword(e.target.value)} required /> {error && ( {error} )} {isLogin ? "Don’t have an account?" : "Already have an account?"}{' '} {isLogin ? "Register" : "Login"}
); }