const userAuth = asyncHandler( async (req,res)=>{
const { email , password } = req.body;
const user = User.findOne({email});
if(user && (await user.matchPassword(password))){
generateToken(res,user._id)
res.status(201).json({
_id:user._id,
name:user.name,
email:user.email
})
}else{
res.status(401);
throw new Error('Incorrect Password or Email');
}
});
{
"message": "user.matchPassword is not a function",
"stack": "TypeError: user.matchPassword is not a functionn at file:///C:/Users/siroh/OneDrive/Desktop/MERN-Auth/server/Controllers/userControllers.js:45:28n at asyncUtilWrap (C:\Users\siroh\OneDrive\Desktop\MERN-Auth\node_modules\express-async-handler\index.js:3:20)n at Layer.handle [as handle_request] (C:\Users\siroh\OneDrive\Desktop\MERN-Auth\node_modules\express\lib\router\layer.js:95:5)n at next (C:\Users\siroh\OneDrive\Desktop\MERN-Auth\node_modules\express\lib\router\route.js:144:13)n at Route.dispatch (C:\Users\siroh\OneDrive\Desktop\MERN-Auth\node_modules\express\lib\router\route.js:114:3)n at Layer.handle [as handle_request] (C:\Users\siroh\OneDrive\Desktop\MERN-Auth\node_modules\express\lib\router\layer.js:95:5)n at C:\Users\siroh\OneDrive\Desktop\MERN-Auth\node_modules\express\lib\router\index.js:284:15n at Function.process_params (C:\Users\siroh\OneDrive\Desktop\MERN-Auth\node_modules\express\lib\router\index.js:346:12)n at next (C:\Users\siroh\OneDrive\Desktop\MERN-Auth\node_modules\express\lib\router\index.js:280:10)n at Function.handle (C:\Users\siroh\OneDrive\Desktop\MERN-Auth\node_modules\express\lib\router\index.js:175:3)"
}