Skip to content

Commit

Permalink
Updated authenticate token for bearer
Browse files Browse the repository at this point in the history
  • Loading branch information
aahmadyar123 committed Aug 24, 2023
1 parent 5b1df2f commit ee89bc8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions backend/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ app.use("/ingredients", ingredientRoutes);
//app.get(..., authenticateToken, function (req, res) => ...);
//middleware to authenticate token, used for protected routes
async function authenticateToken(req, res, next) {
token = req.headers["token"];
token = req.headers.Authorization;
// if token is null return a response with status 401 and end the request
if (token == null) res.status(401).send("Unauthorized");
else {
jwt.verify(token, process.env.TOKEN_SECRET, (err, user) => {
jwt.verify(token.split(' ')[1], process.env.TOKEN_SECRET, (err, user) => {
if (err) res.status(403).send("Forbidden");
else {
req._id = user.id;
Expand Down

0 comments on commit ee89bc8

Please sign in to comment.