title: JavaScript - Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'status')
body: <p>Ive been working on a login script for an app with node and express. Unfortunately i keep getting an the error &quot;Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'status')&quot;. Ive been trying to figure out what im doing wrong. Could someone please point out why this is happening?</p>
  <p>Below is the code for the login script:</p>
  <pre><code>//logic for login page
  app.post('/api/login', async(req, res)=&gt;{
      const {email, password}  = req.body
  
      //get user with the passed email and password
      const user = await userModel.findOne({email}).lean()
      if(!user){
          res.json({status:&quot;error&quot;, error:&quot;Invalid username / password&quot;})
      }
  
      //check if the passwords match
      if(await bcrypt.compare(password, user.password)){
  
          const token = jwt.sign(
              {
                  id:user._id,
                  username:user.username
              },JWT_SECRET
          )
          return res.json({status: &quot;ok&quot;, data:token})
      }
      return res.json({status:&quot;error&quot;, error:&quot;Invalid uswername/password&quot;})
  })
  </code></pre>
  <p>Also the this how i am making the request to the api</p>
  <pre><code>const result = await fetch('/api/login',{
              method: 'POST',
              headers:{
                  'Content-Type':'application/json'
              },
              body:JSON.stringify({
                  email,
                  password
              })
          }).then(res=&gt;{
              res.json()
          })
          if (result.status === 'ok' ){
              alert(&quot;Success&quot;)
              console.log(result.data)
          }else{
              alert(result.error)
          }
      
  }```
  
  </code></pre>