0

Express-validator errors when trying to request with Postman express-validator.[postman errors](https://i.stack.imgur.com/mRPnr.png)

When you try to request from the social. a lot of requests are sent to the network with the code 302 Found socialnet too many requests

router.post('/register',
[
    check('email', 'Invalid email').isEmail(),
    check('password')
    .exists().withMessage('Password is required.')
    .isLength({ min: 6 }).withMessage('Min password length is 6.'),
    check('username')
    .isLength({ max: 20 }).withMessage('User name length must be lesser than 20 chars.'),
],
async (req, res) => {
    try {
        const errors = validationResult(req)

        if (!errors.isEmpty()) {
            console.log(errors)
            return res.status(400).json(new StandartRes(1, 'Invalid data in registration form.', { errors }))
        }

        const { email, password, username, rememberMe } = req.body
        console.log(email, password, username)
        const candidate = await User.findOne({ email })

        if (candidate) {
            return res.status(400).json(new StandartRes(1, 'There is user with this email.'))
        }

        const hashedPassword = await bcrypt.hash(password, 12)
        const user = new User({ email, password: hashedPassword, username, rememberMe })

        await user.save()

        res.status(201).json(new StandartRes(0, 'User is created.', { userId: user.id }))
    } catch (e) {
        res.status(500).json(catchRes)
    }
})

I tried to change the check with .not() to methods .isLength, isEmail and only username started to work properly. another just get rid of errors. but then code finished with catch. Tried to understand what does 302 mean, but cannot get what does temporary location means...

Den
  • 11
  • 1
  • Can you please [read about why text is better than images of text](https://meta.stackoverflow.com/a/285557/11107541) and then [edit](https://stackoverflow.com/questions/75172417/edit) to convert your images of text into actual text? See [/editing-help#code](https://stackoverflow.com/editing-help#code) for how to format code blocks. – RubenSmn Jan 19 '23 at 12:55

0 Answers0