Fix error handling at singup

This commit is contained in:
Adolfo Reyna
2025-02-13 15:45:17 -05:00
parent 50ed0e2c7d
commit 4cab4decb6

View File

@@ -147,7 +147,17 @@ DB.getDB.then((DB) => {
if (!username || !password || !email) return res.json({ status: "Incomplete information!" }); if (!username || !password || !email) return res.json({ status: "Incomplete information!" });
// Check if the new user has an invitation. // Check if the new user has an invitation.
// TODO: Alert admin of signup attempts via email. // TODO: Alert admin of signup attempts via email.
if (!await DB.getInvitation(email)) return res.json({ status: "Not invitation found!" }); if (!await DB.getInvitation(email)){
client_logger.capture({
distinctId: 'app_level',
event: 'server@'+req.method+'@'+req.originalUrl+'@NotInvited',
properties: {
username: username,
email: email,
}
});
return res.json({ status: "Not invitation found!" });
}
let isUserAlreadyRegistered = await DB.getUser(email); let isUserAlreadyRegistered = await DB.getUser(email);
if(isUserAlreadyRegistered && isUserAlreadyRegistered._id) return res.json({status: "This user is already registered"}); if(isUserAlreadyRegistered && isUserAlreadyRegistered._id) return res.json({status: "This user is already registered"});
// Hash password to be stored on the DB. // Hash password to be stored on the DB.
@@ -175,7 +185,14 @@ DB.getDB.then((DB) => {
return await login(req, res); return await login(req, res);
} }
// Error return // Error return
return res.json({ status: response }) client_logger.capture({
distinctId: 'app_level',
event: 'server@'+req.method+'@'+req.originalUrl+'@error',
properties: {
ustatus: newUserObject,
}
});
return res.json({ status: newUserObject })
} }
app.route('/signup').get(async (req, res) => { // Allow get and post to test on browser. app.route('/signup').get(async (req, res) => { // Allow get and post to test on browser.
return await signup(req, res); return await signup(req, res);