fac24 / week1-Joe-Minju-Petra-Peter

A comic book themed Microblogging web site
https://fac-week1-project.herokuapp.com/
3 stars 1 forks source link

Server side validation #18

Open OrianP opened 2 years ago

OrianP commented 2 years ago

Great that you implemented client-side form validation with the required keyword on inputs. The next step would be validating the inputs on the server. At the moment, it's still possible to submit an empty form by removing the required keyword in the dev tools 😈

Screenshot 2022-05-12 at 17 20 03

You could start with a basic check that the req.body object does not contain keys with empty string values before adding to your messages object:

// destructure name and text variables from req.body
// check that both name and text are truthy before adding to messages object
const { name, text } = req.body;
    if (name && text) {
        messages[uid] = req.body;
    }

Then it would be nice to think of a way to inform the user - maybe redirect to a new page with an error message and a link back to the form? 🤔