title: Want to redirect the user if he is logged in
body: <p>Here is client side code that sends a fetch request to the /loginCheck route.</p>
  <pre><code>console.log(&quot;In user login checking function&quot;);
   readAllData('loginDetail')
   .then(function(loginDetails){
      console.log(JSON.stringify(loginDetails[0])); 
      return fetch('/loginCheck', {
        method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json'
      },
      body: JSON.stringify(loginDetails[0])
      })
   .then(function(res){
     console.log(res.status);
   })
   .catch(function(err){
     console.log(err);
   })   
  });
  </code></pre>
  <p>Here is the server side code that checks if the user is logged in and if he is i want to redirect to the main.html page.</p>
  <pre><code>app.post('/loginCheck', (req, res)=&gt;{
    const userName=req.body.nickName;
    console.log(userName);
       Detail.findOne({nickName:userName}, function(err, docs){
        if(err){
          console.log(err);
        }else{
          console.log(&quot;Inside else&quot;);
          if(!docs){
              res.redirect('/');
          }else{
            isLogged=true;
            console.log(isLogged);
            console.log(&quot;Redirecting to the main page&quot;);
            res.redirect('/main.html');
          }
        }
      })
  });
  </code></pre>
  <p>The log statements are getting executed but the redirecting is not working.Could Anyone please point whats going wrong?</p>