From 9a07a69ea5db306cb663890020b7a02151959fe9 Mon Sep 17 00:00:00 2001 From: Marco Kammer Date: Fri, 17 Nov 2023 15:34:52 +0200 Subject: [PATCH] slight change --- server/middleware/authorize.js | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/server/middleware/authorize.js b/server/middleware/authorize.js index 585cb416..30eb2e9f 100755 --- a/server/middleware/authorize.js +++ b/server/middleware/authorize.js @@ -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; }; @@ -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 { @@ -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" });