Skip to content

Commit

Permalink
slight change
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Kammer authored and Marco Kammer committed Nov 17, 2023
1 parent d86738b commit 9a07a69
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions server/middleware/authorize.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ const getTokenFrom = (req) => {

// String 'bearer ' is removed from the authorization header,
// if it exists.
if (authorization && authorization.toLowerCase().startsWith("bearer "))
if (authorization && authorization.toLowerCase().startsWith("bearer ")){
return authorization.substring(7);
}

return null;
};
Expand Down Expand Up @@ -83,25 +84,6 @@ const setUserUsingToken = (decodedToken, res) => {
};
};

// Getting the user information from the database, requires
// a database request. This would run for every service request
const setUserUsingDatabase = async (decodedToken, res, next) => {
try {
const user = await User.findById(decodedToken._id);

res.locals.user = {
_id: user._id,
email: user.email,
firstname: user.firstname,
lastname: user.lastname,
admin: user.admin,
access: user.access,
};
} catch (error) {
next(error);
}
};

// Middleware that checks if the request has a valid token, in the authroziation header.
const requireAuthorization = async (req, res, next) => {
try {
Expand All @@ -122,7 +104,7 @@ const requireAuthorization = async (req, res, next) => {

let decodedToken = {};

decodedToken = jwt.verify(token, secret);
decodedToken = verifyJwt(token, secret);

if (!decodedToken._id) {
return res.status(401).json({ error: "invalid token" });
Expand Down

0 comments on commit 9a07a69

Please sign in to comment.