Week 11
Week 11
Aim:For the above application create authorized end points using JWT (JSON Web Token)
const users = [
];
let students = [
];
app.use(bodyParser.json());
req.user = user;
next();
});
const user = users.find(u => u.username === username && u.password === password);
});
// Authorized endpoints
res.json(students);
});
// Same as before
});
});
// Same as before
});
app.listen(PORT, () => {
});
With this setup, the /login endpoint accepts a username and password and returns a JWT token. You can
then use this token in the Authorization header (Bearer <token>) to access the authorized endpoints
(/students). The authenticateToken middleware verifies the JWT token before allowing access to these
endpoints.
Make sure to replace 'your_secret_key' with a strong, unique secret key in a real-world application.