small update

This commit is contained in:
xfarrow 2024-02-12 17:31:39 +01:00
parent 82a6d5cbe1
commit 2d5ff1137d
2 changed files with 9 additions and 7 deletions

View File

@ -93,7 +93,7 @@ async function login(req, res){
if (person){
const token = generateToken(person.id);
res.status(200).json({ token });
res.status(200).json({token: token });
}
else{
res.status(401).json({error : "Unauthorized"});
@ -109,6 +109,7 @@ async function getPerson(req, res){
.first();
if(user){
// TODO: Check first whether req.jwt.person_id matches req.params.id before requesting the user from the database
if(user.id == req.jwt.person_id || user.enabled){
delete user['password']; // remove password field for security reasons
return res.status(200).send(user);
@ -467,6 +468,7 @@ async function checkUserCredentials(email, password){
}
function generateToken(person_id) {
// The payload the JWT will carry within itself
const payload = {
person_id: person_id
};

View File

@ -15,14 +15,14 @@ async function f1() {
// and then resumes it with the promise result.
async function f2() {
let promise = new Promise((resolve, reject) => {
setTimeout(() => resolve("done!"), 1000)
});
let promise = new Promise((resolve, reject) => {
setTimeout(() => resolve("done!"), 1000)
});
let result = await promise; // wait until the promise resolves (*)
let result = await promise; // wait until the promise resolves (*)
console.log(result); // "done!"
}
console.log(result); // "done!"
}
f2();