mirror of
https://github.com/xfarrow/blink
synced 2025-04-16 17:07:48 +02:00
small update
This commit is contained in:
parent
82a6d5cbe1
commit
2d5ff1137d
@ -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
|
||||
};
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user