Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exports.login = catchAsync(async (req, res, next) => {
- const { email, password } = req.body;
- // 1. Check if email and password exist
- if (!email || !password) {
- return next(new AppError('Please provide email and password!', 400));
- }
- console.log(email); // output => johndoe@example.com It also exists in the database
- console.log(password); // output => doejohn123
- // 2. Check if the user exists and the password is correct
- const user = await User.findOne({ email }).select('+password +active'); // <- right here in this line!
- if (!user || !(await user.correctPassword(password, user.password))) {
- return next(new AppError('Incorrect email or password.', 401));
- }
- // 3. Check if the user has verified his or her id
- if (!user.active) {
- return next(
- new AppError('Sorry you have not yet verified your account.', 401)
- );
- }
- // 4. If everything is fine send token to the client
- createSendToken(user, 200, req, res);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement