From e94914a1525c499d3c71054765f67c13bdaf32bf Mon Sep 17 00:00:00 2001 From: rainbow napkin Date: Thu, 6 Nov 2025 19:36:52 -0500 Subject: [PATCH] Pretty things up a bit, after fixing that nasty profile bug. --- src/controllers/api/account/deleteController.js | 9 +++------ src/controllers/api/account/updateController.js | 9 +++++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/controllers/api/account/deleteController.js b/src/controllers/api/account/deleteController.js index af70cbd..0552da7 100644 --- a/src/controllers/api/account/deleteController.js +++ b/src/controllers/api/account/deleteController.js @@ -33,17 +33,14 @@ module.exports.post = async function(req, res){ const data = matchedData(req); //make sure we're not bullshitting ourselves here. - if(user == null){ - res.status(400); - return res.send('Invalid Session! Cannot delete account while logged out!'); + if(user == null || user.user == null){ + return errorHandler(res, 'You must be logged in to delete your account!', 'unauthorized'); } const userDB = await userModel.findOne({user: user.user}); - if(!userDB){ - res.status(400); - return res.send('Invalid User! Account must exist in order to delete!'); + return errorHandler(res, 'User not found!', 'unauthorized'); } await userDB.nuke(data.pass); diff --git a/src/controllers/api/account/updateController.js b/src/controllers/api/account/updateController.js index 3a04355..bb3fd3f 100644 --- a/src/controllers/api/account/updateController.js +++ b/src/controllers/api/account/updateController.js @@ -46,6 +46,12 @@ module.exports.post = async function(req, res){ const {field, change} = data; const {user} = req.session; + //If the user is null + if(user == null || user.user == null){ + //BEFORE YOU BREAK MY HEART!!! + return errorHandler(res, 'You must be logged in to preform this action!', 'unauthorized'); + } + const userDB = await userModel.findOne({user: user.user}); const update = {}; @@ -86,8 +92,7 @@ module.exports.post = async function(req, res){ res.status(200); return res.send(update); }else{ - res.status(400); - return res.send({errors: [{msg:"User not found!"}]}); + return errorHandler(res, 'User not found!', 'unauthorized'); } }else{ res.status(400);