In user.controller the login should not send the seponse and then return next(). This causes the error "Cannot set headers after they are sent to the client ".
it should be:
export function login(req, res, next) {
if (req.user) return res.status(200).json(req.user)
next()
}
instead of
export function login(req, res, next) {
res.status(200).json(req.user)
return next()
}