My console returns: Uncaught (in promise) SyntaxError: Unexpected end of JSON input
and my terminal returns: { categoryId: undefined }
This is my my routes:
router.get('/getAll', auth.verify, (req, res) => {
const user = auth.decode(req.headers.authorization);
const categoryId = req.params.categoryId
UserController.getCat({ categoryId })
.then(category => res.send(category))
})
This is my controller:
module.exports.getCat = (params) => {
console.log(params)
return User.findById(params.categoryId)
.then(resultFromFindById => resultFromFindById)
}
I want to get all the data using this fetch on my component, please help me to identify whats the problem.. seems like there's nothing wrong with my syntax
useEffect(() => {
fetch(`${process.env.NEXT_PUBLIC_API_URL}/users/getAll`, {
headers: {
'Authorization': `Bearer ${localStorage.getItem('token')}`
},
})
.then(res => res.json())
.then(data => {
if(data) {
console.log(data)
}
})
}, [])