Closed ecumene closed 3 years ago
module.exports = async (req, res, next) => { try { const jwtToken = await req.header("Authorization"); if (!jwtToken) { res.status(403).json({ message: "No access token" }); } const payload = await jwt.verify(jwtToken.replace("Bearer ", ""), process.env.jwtSecret); res.json({ "id": payload.id }); } catch (err) { res.status(500).json({ message: err.message }); } next(); };
https://stackoverflow.com/questions/43915379/i-need-to-replace-bearer-from-the-header-to-verify-the-token
Used replace function as demonstrated above. Endpoints that use 'authorization.js' as middleware function now working correctly.
authorize now returns user id, which is then used to fetch relevant data from API.
https://stackoverflow.com/questions/43915379/i-need-to-replace-bearer-from-the-header-to-verify-the-token