Catching werid cornercase on which users don't have profiles.
This commit is contained in:
6
index.js
6
index.js
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user