dimanche 9 mai 2021

req.session.cart always gives undefined even though i pass objects in cart array

I am trying to create cart , therefore i first check for cart if it is undefined i create cart and add objects in it ,, but even thoug i add data inside req.session.cart where cart is an array it always gives undefined ,

router.get("/cartItem/:id",(req,res)=>{
  pizza.findOne({_id:req.params.id}).then((docs) => {

   
if(typeof req.session.cart == "undefined"){
  console.log(typeof req.session.cart)


  req.session.cart = []

  req.session.cart.push({


    message:"hello world"

  })


 }else{


  console.log("increase quantity code !!! ")
 }


})


})

cart always console.logs undefiend even though i add array of objects

as it can bee seen the cart has an array of objects but still when i check for typeof req.session.cart it results in undefined




Aucun commentaire:

Enregistrer un commentaire