I am using passport-local for user authentication. When I try to get logged in User it works in postman but gives error message which i set to "You need to be logged in first to get data". My user is successfully logging in from vue js but when i try to get logged in user its gives my error message.
here is my route :
router.get('/jobs', auth ,async(req, res) => {
const jobs = await Job.find({}).sort({
createdAt : -1
})
console.log(req.user)//This is working in postman but gives error in vue js
res.send(jobs)
})
I am using cors and specifying origin and set credentials to true.
here is my frontend request :
try{
const res = await axios.get('http://localhost:3000/jobs', {
withCredentials : true
})
this.jobs = await res.data
console.log(this.jobs) // It gives my error message even i am logged in
}catch(error) {
if(error.response) {
this.message = error.response.data
}
}
