title: Thymeleaf with Spring Security - how to check if user is logged in or not?
body: <p>I'm using Spring Boot with Thymeleaf and Spring Security.
  I've got a simple view with a login link. When the user logs in, I'd like to change login link to logout link.</p>
  <p>I tried:</p>
  <pre><code>&lt;div sec:authorize=&quot;#{isAuthenticated()}&quot;&gt;
    &lt;a th:href=&quot;@{/logout}&quot;&gt;Log out&lt;/a&gt;
  &lt;/div&gt;
  &lt;div sec:authorize=&quot;#{isAnonymous()}&quot;&gt;
    &lt;a th:href=&quot;@{/login}&quot;&gt;Log in&lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  <p>but it's not working - it displays both links.</p>
  <p>EDIT:
  I <strong>solved</strong> it. I had to register Thymeleaf dialect. In order to do this, I created a new config class, that creates SpringSecurityDialect bean:</p>
  <pre><code>@Configuration
  public class ThymeleafConfig {
  
      @Bean
      public SpringSecurityDialect springSecurityDialect(){
          return new SpringSecurityDialect();
      }
  }
  </code></pre>