Last active
July 10, 2019 22:02
-
-
Save aktasfatih/f067fdad0b2a29537dbb703d7a675412 to your computer and use it in GitHub Desktop.
Route example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.post('/userInfo', function(req, res){ // Route for handling the request | |
jwt.verify(req.body.token, JWT_SECRET, (err, decoded) => { // Checking if the JWT token of the user is valid | |
if (err){ // Handling error | |
res.json({ | |
"info" : "Error0" | |
}); | |
}else{ | |
if(typeof decoded.username === "undefined"){ // Checking if username is defined in the request | |
res.json({ // Handling the error | |
"info" : "Error1" | |
}); | |
}else{ | |
var query = "SELECT u.NAME AS name, u.last_name, u.about, s.NAME AS school, u.profile_pic, u.goldMedals, u.silverMedals, u.bronzeMedals FROM Users u\ | |
LEFT JOIN Schools s ON u.School = s.school_id WHERE u.username = ?"; // MYSQL query | |
connection.query(query,[decoded.username], function(error, rows, fields){ // Querying | |
if(error){ // Handling any error occured during querying | |
console.log("There was an error: " + error.stack); | |
res.json({res:false}); | |
return; | |
} | |
var info = rows[0]; // Returning the query. | |
res.json(info); | |
}); | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment