Catching werid cornercase on which users don't have profiles.
This commit is contained in:
34
index.js
34
index.js
@@ -175,20 +175,26 @@ 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" });
|
||||||
// Store a new session loging on DB, and use ID as session ID
|
try {
|
||||||
const sessionObj = await DB.newSession(user._id);
|
// Store a new session loging on DB, and use ID as session ID
|
||||||
// Create coockies with information for Auth
|
const sessionObj = await DB.newSession(user._id);
|
||||||
res.cookie('user_sid', user._id, cookiesOptions);
|
// Create coockies with information for Auth
|
||||||
res.cookie('session_id', sessionObj.insertedId, cookiesOptions);
|
res.cookie('user_sid', user._id, cookiesOptions);
|
||||||
// Chooses the most recent update profile as current active profile
|
res.cookie('session_id', sessionObj.insertedId, cookiesOptions);
|
||||||
const latestUpdatedProfile = await DB.latestProfile(user._id);
|
// Chooses the most recent update profile as current active profile
|
||||||
res.cookie('profile_id', latestUpdatedProfile._id, cookiesOptions);
|
const latestUpdatedProfile = await DB.latestProfile(user._id);
|
||||||
return res.json({
|
res.cookie('profile_id', latestUpdatedProfile._id, cookiesOptions);
|
||||||
status: "ok",
|
return res.json({
|
||||||
user_sid: user._id,
|
status: "ok",
|
||||||
session_id: sessionObj.insertedId,
|
user_sid: user._id,
|
||||||
profile_id: latestUpdatedProfile._id
|
session_id: sessionObj.insertedId,
|
||||||
});
|
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