unable to iterate the user data
router.post("/signin",(req,res)=>{
const{email,password}=req.body;
if(!email||!password){
return res.status(404).json({error:"enter all the feilds"})
}
User.findOne({email:email}).then(foundUser=>{
if(!foundUser){
return res.status(422).json({error:"user not found"})
}
bcrypt.compare(password,foundUser.password).then(match=>{
if(match){
// res.json({message:"signin sucessfully"})
const token=jwt.sign({_id:foundUser._id},JWT_SECRET)
const [_id,name,email]=foundUser //here is the error
return res.json({token,user:foundUser._id})
}
return res.status(422).json({message:"email and password doesnt match"})
})
}).catch(err=>{
console.log(err)
})
})
error: (node:27268) UnhandledPromiseRejectionWarning: TypeError: foundUser is not iterable at G:\courses\implementation\instagram\backend\routers\auth.js:62:48 (node:27268) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
Aucun commentaire:
Enregistrer un commentaire