({
isOpen,
onClose,
defaultMode = 'login',
onLoginSuccess,
})
| 50 | } |
| 51 | |
| 52 | const AuthModal: React.FC<AuthModalProps> = ({ |
| 53 | isOpen, |
| 54 | onClose, |
| 55 | defaultMode = 'login', |
| 56 | onLoginSuccess, |
| 57 | }) => { |
| 58 | const { t } = useTranslation(); |
| 59 | const navigate = useNavigate(); |
| 60 | const location = useLocation(); |
| 61 | const [mode, setMode] = useState<'login' | 'signup'>(defaultMode); |
| 62 | |
| 63 | // Update mode when defaultMode prop changes |
| 64 | useEffect(() => { |
| 65 | setMode(defaultMode); |
| 66 | }, [defaultMode]); |
| 67 | |
| 68 | const [showPassword, setShowPassword] = useState(false); |
| 69 | const [formData, setFormData] = useState({ |
| 70 | email: '', |
| 71 | password: '', |
| 72 | name: '', |
| 73 | }); |
| 74 | |
| 75 | const [passwordStrength, setPasswordStrength] = |
| 76 | useState<PasswordStrength | null>(null); |
| 77 | const [passwordRequirements, setPasswordRequirements] = |
| 78 | useState<PasswordRequirements | null>(null); |
| 79 | |
| 80 | const { login, signup, isLoading, error, clearError } = useAuth(); |
| 81 | const { showSuccess } = useNotifications(); |
| 82 | |
| 83 | // Handle close with navigation logic for settings page |
| 84 | const handleClose = () => { |
| 85 | // If we're on the settings page, navigate to home instead of just closing |
| 86 | if (location.pathname.startsWith('/settings')) { |
| 87 | navigate('/'); |
| 88 | } else { |
| 89 | onClose(); |
| 90 | } |
| 91 | }; |
| 92 | |
| 93 | // Load password requirements from frontend validator (no API call needed) |
| 94 | useEffect(() => { |
| 95 | if (isOpen) { |
| 96 | setPasswordRequirements(PasswordValidator.getPasswordRequirements()); |
| 97 | } |
| 98 | }, [isOpen]); |
| 99 | |
| 100 | // Instant password strength checker using frontend validator |
| 101 | const checkPasswordStrength = useCallback( |
| 102 | (password: string) => { |
| 103 | if (!password || password.length < 1) { |
| 104 | setPasswordStrength(null); |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | // Use frontend validator for instant feedback |
| 109 | const result = PasswordValidator.validatePasswordWithPersonalInfo( |
nothing calls this directly
no test coverage detected