EJS conditional rendering

How to render html if user is logged in or not. I have tried if, else but it doesn't work as i want it to be. Is there another way of doing the same.

    <% if(typeof(user) === "defined" ){ %>
      <li class="navlist-item user">
        <a href="/user/<%= user.id %> "> <i class="far fa-user"> <%= user.name %> </i> </a>
      </li>
  <% } %>
  <% if(typeof(user) != "undefined" ){ %>
          <li class="navlist-item">
            <span class="get-started">
              <a href="/auth/register"> Sign Up</a>
            </span>
          </li>
          <li class="navlist-item">
            <span class="get-started">
              <a href="/auth/login">
                <span> Log In</span>
              </a> </span>
 <% } %> 

 <% if(typeof user !== 'undefined'){ %>
      <li class="navlist-item user">
        <a href="/user/<%= user.id %> "> <i class="far fa-user"> <%= user.name %> </i> </a>
      </li>
  <% } else { %>
          <li class="navlist-item">
            <span class="get-started">
              <a href="/auth/register"> Sign Up</a>
            </span>
          </li>
          <li class="navlist-item">
            <span class="get-started">
              <a href="/auth/login">
                <span> Log In</span>
              </a> </span>
 <% } %>