0
<div class="header__top__right__auth">
                            
                            <span th:if ="${session.isEmpty()}">
                              <!--  <a href="login"><i class="fa fa-user"></i> Login</a></span> -->
                               <a href="login"><i class="fa fa-user"></i> Login</a></span>
                            <span th:if = "${!session.isEmpty()}">
                                <span th:text="${session.uid}"></span>
                                <a href="logout"><i class="fa fa-user"></i>Logout</a></span>
                            </div>

spring boot/thymleaf is their another method when that is in session its showing directly logout is their any other method to slove my problem

Jens
  • 67,715
  • 15
  • 98
  • 113
Ramu
  • 9
  • How can this question may be already edited, is there is still spelling and grammar error? My adjustment is not being accepted. – m19v Oct 12 '22 at 06:42

1 Answers1

0

In your html tag add namespace,

xmlns:sec="http://www.thymeleaf.org/extras/spring-security"

In pom.xml, ensure you have the following dependency

<dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
<dependency>
            <groupId>nz.net.ultraq.thymeleaf</groupId>
            <artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>

and then in html, you can use tag sec:authorize , like:

<div sec:authorize="isAnonymous()">
     <a href="login"><i class="fa fa-user"></i>Login</a>
</div>
<div sec:authorize="isAuthenticated()">
     <a href="logout"><i class="fa fa-user"></i>Logout</a>
</div>
Chetan Ahirrao
  • 1,454
  • 11
  • 16