mirror of
https://github.com/xfarrow/blink
synced 2025-04-24 18:18:40 +02:00
small update
This commit is contained in:
parent
82a6d5cbe1
commit
2d5ff1137d
@ -93,7 +93,7 @@ async function login(req, res){
|
|||||||
|
|
||||||
if (person){
|
if (person){
|
||||||
const token = generateToken(person.id);
|
const token = generateToken(person.id);
|
||||||
res.status(200).json({ token });
|
res.status(200).json({token: token });
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
res.status(401).json({error : "Unauthorized"});
|
res.status(401).json({error : "Unauthorized"});
|
||||||
@ -109,6 +109,7 @@ async function getPerson(req, res){
|
|||||||
.first();
|
.first();
|
||||||
|
|
||||||
if(user){
|
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){
|
if(user.id == req.jwt.person_id || user.enabled){
|
||||||
delete user['password']; // remove password field for security reasons
|
delete user['password']; // remove password field for security reasons
|
||||||
return res.status(200).send(user);
|
return res.status(200).send(user);
|
||||||
@ -467,6 +468,7 @@ async function checkUserCredentials(email, password){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generateToken(person_id) {
|
function generateToken(person_id) {
|
||||||
|
// The payload the JWT will carry within itself
|
||||||
const payload = {
|
const payload = {
|
||||||
person_id: person_id
|
person_id: person_id
|
||||||
};
|
};
|
||||||
|
@ -15,14 +15,14 @@ async function f1() {
|
|||||||
// and then resumes it with the promise result.
|
// and then resumes it with the promise result.
|
||||||
async function f2() {
|
async function f2() {
|
||||||
|
|
||||||
let promise = new Promise((resolve, reject) => {
|
let promise = new Promise((resolve, reject) => {
|
||||||
setTimeout(() => resolve("done!"), 1000)
|
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();
|
f2();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user