Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const jwt = require('jsonwebtoken');
- module.exports = (req, res, next) => {
- try {
- const token = req.headers.authorization.split(" ")[1];
- const decoded = jwt.verify(token, process.env.JWT_SECRET);
- req.userData = decoded;
- next();
- } catch (error) {
- return res.status(401).json({
- message: 'Authentication Failed!',
- });
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment