title: Login system works properly in Postman but in not in browser
body: <p>Here is my router</p>
  <pre><code> router.post(&quot;/login&quot;, async (req, res) =&gt; 
      {
          try
          {
              const user = await User.findByCredentials(req.body.email, req.body.password)  
              // console.log(user)
              const token = await user.generateAuthToken()
              // console.log(token)
              res.redirect(&quot;/takvim&quot;)
          }
          catch(e)
          {
              res.status(400).redirect(&quot;/&quot;)
          }
      })
  </code></pre>
  <p>Here is my user model that I use in the function above</p>
  <pre><code>UserSchema.methods.generateAuthToken = async function () 
  {
      const user = this
      const token = jwt.sign({_id: user._id.toString()}, &quot;secret&quot;)
      user.tokens = user.tokens.concat({token})
      await user.save()
      return token
  }
  
  UserSchema.statics.findByCredentials =  async function (emails, passwords)
  {    
    const user = await User.findOne({email: emails})
    console.log(user)
    const isMatch = await bcrypt.compare(passwords, user.password)
    if(!isMatch)
    {
      throw new Error(&quot;unable to login&quot;)
    }
    return user   
  }
  </code></pre>
  <p>I am making the request from frontend using a button</p>
  <pre><code>$uyeolForm.addEventListener(&quot;submit&quot;, () =&gt; 
  {
      if(!$uyeolFormEmail.value.includes(&quot;.com&quot;))
      {
         return $uyeolFormHata.innerHTML = &quot;email geçersiz&quot; 
      }
      const xhr = new XMLHttpRequest();
      let form = JSON.stringify({
      email: $uyeolFormEmail.value,
      password: $uyeolFormPassword.value
      });
      xhr.open(&quot;POST&quot;, &quot;/login&quot;)
      xhr.setRequestHeader('Content-type', 'application/json')
      xhr.send(form);
  })
  </code></pre>
  <p>Problem is when I am using the postman, application redirects me to the page i want and doesn't give an error.
  When I send the request with button it still finds user but it doesn't redirect me to the page I expect and in the console i see the user(expected) and <code>null</code> which is not expected.</p>
  <p>Thanks to everyone.</p>