mekasu0124

Untitled

Oct 17th, 2024
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const jwt = require('jsonwebtoken');
  2.  
  3.  
  4. module.exports = (req, res, next) => {
  5.   try {
  6.     const token = req.headers.authorization.split(" ")[1];
  7.     const decoded = jwt.verify(token, process.env.JWT_SECRET);
  8.  
  9.     req.userData = decoded;
  10.    
  11.     next();
  12.   } catch (error) {
  13.     return res.status(401).json({
  14.       message: 'Authentication Failed!',
  15.     });
  16.   }
  17. };
  18.  
Advertisement
Add Comment
Please, Sign In to add comment