// const User = require('../../models/User');
const mongoose = require("mongoose");
const User = mongoose.model("User") 


const authenticateUserByToken = (req,res,next) => { 
    console.log(req.header);
    const token = req.header('auth-token'); 
    User.findByToken(token)
        .then(user => { 
            if (user) { 
                req.user = user
                req.token = token
                next()
            }
            else {
                return res.status(401).send('token not found')
            }
        })
        .catch(err => { 
            return res.send("err")
        })

}
module.exports = authenticateUserByToken