title: hide login and sign up buttons and display logout button when user logs in using node js and ejs
body: <p>I've successfully created my first web application using node js, ejs and mongodb.</p>
  <p>I want to hide my login/sign up links when user logs in and want to display logout button in my header file.</p>
  <p>Anybody got a solution? I've already tried <a href="https://stackoverflow.com/questions/12457615/expressjs-how-to-show-hide-a-div-in-case-user-its-logged">Expressjs how to show / hide a div in case user its logged</a>
  But for some reason, the user variable in ejs file is initialising to null, so only one case is exectuting</p>
  <p>Here is my header.ejs file:</p>
  <pre><code>&lt;h1&gt;&lt;a href=&quot;/&quot;&gt;RideShare&lt;/a&gt;&lt;/h1&gt;
  
  &lt;ul&gt;
      
      
      &lt;li&gt;&lt;a href=&quot;/find&quot;&gt;Find a ride&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;/create&quot;&gt;Create a ride&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;/myrides&quot;&gt;My rides&lt;/a&gt;&lt;/li&gt;
      &lt;%if (!user) { %&gt;
          &lt;li&gt;&lt;a href=&quot;/login&quot;&gt;Sign in&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;/register&quot;&gt;Sign Up&lt;/a&gt;&lt;/li&gt;
          &lt;% }else{ %&gt;
              &lt;form action=&quot;/logout?_method=DELETE&quot; method=&quot;POST&quot;&gt;
                  &lt;button type=&quot;submit&quot;&gt;Log Out&lt;/button&gt;
              &lt;/form&gt;
              &lt;%}%&gt;
      
  &lt;/ul&gt;
  
  </code></pre>