-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a322e6f
commit 12ca892
Showing
43 changed files
with
5,460 additions
and
5,114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,22 @@ | ||
const mongoose = require('mongoose'); | ||
const User = require('../database/User'); | ||
|
||
const login = async(req, res, next) => { | ||
const {phoneNo, password, userType} = req.body; | ||
console.log(phoneNo) | ||
console.log(password) | ||
console.log(userType) | ||
const identifiedUser = await User.find({phoneNo, password, userType}).exec().catch((error) => { | ||
console.log("Error catched.", error); | ||
const login = async (req, res, next) => { | ||
const { phoneNo, password, userType } = req.body; | ||
const identifiedUser = await User.find({ phoneNo, password, userType }) | ||
.exec() | ||
.catch((error) => { | ||
return next(error); | ||
}); | ||
console.log(identifiedUser); | ||
if(identifiedUser.length===0){ | ||
const error = Error('Invalid credentials.'); | ||
error.code = 401; | ||
return next(error); | ||
} | ||
res.json({ | ||
message: 'Logged in successfully!', | ||
user: identifiedUser[0] | ||
if (identifiedUser.length === 0) { | ||
return res.status(404).send({ | ||
message: 'Invalid Credentials', | ||
}); | ||
} | ||
} | ||
res.json({ | ||
message: 'Logged in successfully!', | ||
user: identifiedUser[0], | ||
}); | ||
}; | ||
|
||
exports.login = login; | ||
exports.login = login; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.