Catching werid cornercase on which users don't have profiles.

This commit is contained in:
Adolfo Reyna
2025-02-02 23:55:58 -05:00
parent 9ab922f765
commit 0ca589cbe8

View File

@@ -175,6 +175,7 @@ DB.getDB.then((DB) => {
// TODO: Also add salt parameter here. // TODO: Also add salt parameter here.
const isSamePassword = await bcrypt.compare(password, user.password); const isSamePassword = await bcrypt.compare(password, user.password);
if (!isSamePassword) return res.json({ status: "incorrect password" }); if (!isSamePassword) return res.json({ status: "incorrect password" });
try {
// Store a new session loging on DB, and use ID as session ID // Store a new session loging on DB, and use ID as session ID
const sessionObj = await DB.newSession(user._id); const sessionObj = await DB.newSession(user._id);
// Create coockies with information for Auth // Create coockies with information for Auth
@@ -189,6 +190,11 @@ DB.getDB.then((DB) => {
session_id: sessionObj.insertedId, session_id: sessionObj.insertedId,
profile_id: latestUpdatedProfile._id profile_id: latestUpdatedProfile._id
}); });
} catch (error) {
console.error(error);
return res.json({ status: "Error on this User Profile, please contact admin." });
}
} }
app.route('/login').get(async (req, res) => { app.route('/login').get(async (req, res) => {
return await login(req, res); return await login(req, res);