This repository has been archived on 2025-11-04. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
know-it-all/server/routes/auth/GetUserDetails.js

20 lines
567 B
JavaScript

const { User } = require('../../db/models/index');
async function GetUserDetails(req, res, next) {
const user = req.user;
const userID = req.params.userID;
// Immediately respond if user is querying themselves
if (user.id == userID) {
return res.send(user);
}
// Retrieve user while excluding sensitive information
const result = await User.findOne({
where: { id: userID },
attributes: { exclude: ['password', 'createdAt', 'updatedAt'] },
});
return res.send(result);
}
module.exports = GetUserDetails;