Today's focus: improved backend structure using proper error handling, created a global error middleware, and added validation for request bodies using Joi. Cleaned up the authentication middleware as well.
next(error) to propagate errors(err, req, res, next)const Joi = require("joi");
const signupSchema = Joi.object({
username: Joi.string().min(3).max(30).required(),
email: Joi.string().email().required(),
password: Joi.string().min(6).required()
});
const validateSignup = (req, res, next) => {
const { error } = signupSchema.validate(req.body);
if (error) return res.status(400).send(error.details[0].message);
next();
};