text: const jwt = require('jsonwebtoken');
  const {JWT_USER} = require('../config/keys')
  
  //mongoDB
  const mongoose = require('mongoose');
  const User = mongoose.model("User");
  
  module.exports = (req,res,next)=>{
      const {authorization} = req.headers;
  
      // authorization === Bearer qpmcskjvbhjdfziod
      if(!authorization){
          return res.status(401).json({error:"User must be logged in!"})
      }
      const token = authorization.replace("Bearer ","");
  
      jwt.verify(token, JWT_USER, (err,payload) =>{
          if(err) {
              return res.status(401).json({error:"User must be logged in!"})
          }
  
          const {_id} = payload;
          User.findById(_id).then(userdata=>{
              req.user = userdata
              next()
          })
      })
  
  }