Advertisement
FrostZTech

Returns null!

Oct 22nd, 2020
1,850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. exports.login = catchAsync(async (req, res, next) => {
  2.   const { email, password } = req.body;
  3.  
  4.   // 1. Check if email and password exist
  5.   if (!email || !password) {
  6.     return next(new AppError('Please provide email and password!', 400));
  7.   }
  8.  
  9.   console.log(email);   // output => johndoe@example.com    It also exists in the database
  10.   console.log(password);    // output => doejohn123
  11.  
  12.   // 2. Check if the user exists and the password is correct
  13.   const user = await User.findOne({ email }).select('+password +active');   // <- right here in this line!
  14.  
  15.   if (!user || !(await user.correctPassword(password, user.password))) {
  16.     return next(new AppError('Incorrect email or password.', 401));
  17.   }
  18.  
  19.   // 3. Check if the user has verified his or her id
  20.   if (!user.active) {
  21.     return next(
  22.       new AppError('Sorry you have not yet verified your account.', 401)
  23.     );
  24.   }
  25.  
  26.   // 4. If everything is fine send token to the client
  27.   createSendToken(user, 200, req, res);
  28. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement