Res.json() not returning value back to api

client

const {data} = await axios.create({baseURL:`http://127.0.0.1:5000/api`}).post("/seller/login",{         
        sellerMobile,            
        sellerEmail,
        password
    },headers:{
            'Content-type':'application/json'
        })

server.js // Main File at backend

const app = express()
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended:false}))
app.use(cors())
if(process.env.NODE_ENV==="development"){
         app.use(morgan("dev"))
}
app.use("/api/seller",sellerRoutes)

sellerRoutes.js //Route file

const router = express.Router()
router.post("/login",authSeller)

authSeller.js // Controller file

const authSeller = asyncHandler(async(req,res) => {    
const {email,password} = req.body

const seller = await Seller.findOne({sellerEmail:email})

if(seller){
    console.log("seller data",seller) // shows the data on backend console
    return res.status(201).send({
        _id : seller._id,            
        sellerEmail:seller.sellerEmail, 
        mobile:seller.mobile,
    })        
}else{
    res.status(401)
    throw new Error ('Invalid email or password')
}
})

I’m not receiving the data back in called API.

Are you not hitting the else code on the backend?

Shouldn’t it be sellerEmail and not email for the destructuring of the body?

backend console shows the value the seller object
but forntend console does’t get anything i,e, console.log(data) in client
shows nothing…
Please help

no getting the values in backend console yeah it should be sellerEmail.
but still not getting back the data…
more over registering user works fine which save user data and gets the data after saving the same data with id from backend…
getting headache now.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.