Skip to content

Commit

Permalink
Fix for need a route to check if a username is valid for any app sidd…
Browse files Browse the repository at this point in the history
  • Loading branch information
rag594 committed Sep 5, 2019
1 parent 58586a8 commit 3e31b5d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions controllers/user-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,22 @@ async function verifyAccessToken(accessToken, res) {
return res.send;
}

async function isUserRegistered(req,res) {
try{
const checkForExistingUser = await User.findOne({
email: req.body.email
})
if(!checkForExistingUser) {
res.status(200).json({"present":false});
}
res.status(200).json({"present":true});
} catch (err) {
console.log('Mongo error', err);
return res.status(500).send()
}
}

exports.saveUserIfNew = saveUserIfNew;
exports.findUserAndAuthenticate = findUserAndAuthenticate;
exports.verifyAccessToken = verifyAccessToken;
exports.isUserRegistered = isUserRegistered;
6 changes: 6 additions & 0 deletions routes/user.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,11 @@ router.post('/verify', (req, res) => {
return response;
});

router.post('/email/verify', (req, res) => {
//console.log("Req",req);
const response = userController.isUserRegistered(req,res);
return response;
})


module.exports = router;

0 comments on commit 3e31b5d

Please sign in to comment.