2021年1月14日星期四

"UnhandledPromiseRejectionWarning: Error: Illegal arguments: undefined, string"

Hey I was trying to follow up this "Build A Node.js API Authentication With JWT Tutorial" on youtube. For some reason the post request of '/register', is giving me this error "UnhandledPromiseRejectionWarning: Error: Illegal arguments: undefined, string". Below you can find the code

const router = require('express').Router();  const User = require('../user');  const {resigerValidate} = require('../validation');  const bcrypt = require('bcryptjs')    router.post('/register', async (req, res)=>{      // doing validation from validation.js      const {error} = resigerValidate(req.body);      const salt = await bcrypt.genSalt(10);      const hashedPassword = await bcrypt.hash(req.body.password, salt);      if (error) {          return res.status(400).send(error.details[0].message);      }      // checks if the email already exists in the database (partially working)      const emailExists = await User.findOne({email: req.body.email});      if (emailExists){          return res.status(400).send('This email already exists in the database !!!');      }       // user creation      const user = new User({          name: req.body.name,          email: req.body.email,          password: hashedPassword      });      try{          const savedUser = await user.save();          res.send(savedUser);      }catch(err){          res.status(400).send(err);      }          });        module.exports = router;  
https://stackoverflow.com/questions/65729865/unhandledpromiserejectionwarning-error-illegal-arguments-undefined-string January 15, 2021 at 10:58AM

没有评论:

发表评论