FE/html

[Thymeleaf] 로그인, 로그아웃 버튼

잔망루피 2021. 11. 19. 21:16

🦔 먼저

implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'

build.gradle의 dependencies에 추가해줬다.

 

 

<a sec:authorize="!isAuthenticated()" class="btn btn-info" th:href="@{/user/login}">로그인</a>
    <form th:action="@{/logout}" method="POST" sec:authorize="isAuthenticated()">
        <button class="btn btn-info" type="submit">로그아웃</button>
    </form>

로그아웃할 때는 따로 컨트롤러를 만들지 않아도 된다.

로그인과 로그아웃 버튼 둘중 하나만 보인다.

 

 

 

참고 👇

https://www.thymeleaf.org/doc/articles/springsecurity.html

 

Thymeleaf + Spring Security integration basics - Thymeleaf

Have you switched to Thymeleaf but your login and error pages are still using JSP? In this article we will see how to configure your Spring application to use Thymeleaf for login and error pages. All the code seen here comes from a working application. You

www.thymeleaf.org

 

반응형