Let’s create an endpoint (/me
) that returns the user their information `only if they send their
app.get("/me", (req, res) => {
const token = req.headers.authorization;
const user = users.find(user => user.token === token);
if (user) {
res.send({
username: user.username
})
} else {
res.status(401).send({
message: "Unauthorized"
})
}
})