- Modify /login router to accept username and password as query string parameter
- Read data from user.json file
- If username and passsword is valid then send resonse as below
{
status: true,
message: "User Is valid"
}
- If username is invalid then send resonse as below
{
status: false,
message: "User Name is invalid"
}
- If passsword is invalid then send resonse as below
{
status: false,
message: "Password is invalid"
}
*/
router.get('/login', (req,res) => {
res.send('This is login router');
});
user.json
"id":1,
"name":"Leanne Graham",
"username":"bret",
"password":"bret@123",
"email":"[email protected]",
"address":{
"street":"Kulas Light",
"suite":"Apt. 556",
"city":"Gwenborough",
"zipcode":"92998-3874",
"geo":{
"lat":"-37.3159",
"lng":"81.1496"
}
},
"phone":"1-770-736-8031 x56442",
"website":"hildegard.org",
"company":{
"name":"Romaguera-Crona",
"catchPhrase":"Multi-layered client-server neural-net",
"bs":"harness real-time e-markets"
}
}
require json file in your file and set variable name to jsondata
router.get("/login", (req, res) => {
if (req.username === jsonData.username && req.password === jsonData.password)
res.status(200).json({
status: true,
message: "User Is valid"
});
else if (req.username === jsonData.username)
res.status(200).json({
status: false,
message: "Password is invalid"
});
else
res.status(200).json({
status: false,
message: "User Name is invalid"
});
});
Get Answers For Free
Most questions answered within 1 hours.