first commit
This commit is contained in:
parent
b8838a303b
commit
8f8ceeb78c
@ -38,19 +38,20 @@ export const loginUser = catchAsyncErrors(async (req, res, next) => {
|
|||||||
// checking if user has given password and email both
|
// checking if user has given password and email both
|
||||||
|
|
||||||
if (!email || !password) {
|
if (!email || !password) {
|
||||||
return next(new ErrorHander("Please Enter Email & Password", 400));
|
return next(res.status(400).json({ message: 'Please Enter Email & Password' }));
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = await User.findOne({ email }).select("+password");
|
const user = await User.findOne({ email }).select("+password");
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return next(new ErrorHander("Invalid email or password", 401));
|
return res.status(400).json({ message: 'Invalid Email or Password' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const isPasswordMatched = await user.comparePassword(password);
|
const isPasswordMatched = await user.comparePassword(password);
|
||||||
|
|
||||||
if (!isPasswordMatched) {
|
if (!isPasswordMatched) {
|
||||||
return next(new ErrorHander("Invalid email or password", 401));
|
return res.status(400).json({ message: 'Invalid Email or Password' });
|
||||||
}
|
}
|
||||||
// const token = user.getJWTToken();
|
// const token = user.getJWTToken();
|
||||||
// res.status(201).json({
|
// res.status(201).json({
|
||||||
|
Loading…
Reference in New Issue
Block a user