Skip to content

Enhancement: Real-time Form Validation - #3

@codeCraft-Ritik

Description

@codeCraft-Ritik

Issue: The Login.jsx component sends requests to the server even if the password is too short or fields are improperly formatted.

Solution: Add client-side checks to provide immediate feedback via toast notifications before the network request is initiated.

File Path: Imagify/client/src/components/Login.jsx

const onSubmitHandler = async (e) => {
    e.preventDefault();
    
    // Front-end validation
    if (password.length < 8) {
        return toast.error("Password must be at least 8 characters");
    }

    try {
        if (state === 'Login') {
            const { data } = await axios.post(backendUrl + '/api/user/login', { email, password });
            // ... handle login
        } else {
            const { data } = await axios.post(backendUrl + '/api/user/register', { name, email, password });
            // ... handle register
        }
    } catch (error) {
        toast.error(error.message);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions