Quando clico em logout, ele desloga e volta pra tela de login, porém preciso inserir os dados de login duas vezes pq ele redireciona para /login?logout e aparece que fui deslogado na primeira tentativa, na segunda funciona normalmente.
<nav>
<a sec:authorize="!isAuthenticated()" href="/login">Entrar</a>
<a onclick="document.querySelector('#f-logout').submit()" sec:authorize="isAuthenticated()" href="#">Sair</a>
<form id="f-logout" th:action="@{/logout}" method="post"></form>
</nav>
<h1>Please Log In</h1>
<div th:if="${param.error}">
Invalid username and password.</div>
<div th:if="${param.logout}">
You have been logged out.</div>
<form th:action="@{/login}" method="post">
<div>
<input type="text" name="username" placeholder="Username"/>
</div>
<div>
<input type="password" name="password" placeholder="Password"/>
</div>
<input type="submit" value="Log in" />
</form>
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().authenticated()
.and().formLogin(form ->
form.loginPage("/login")
.permitAll()
)
.logout(logout -> logout.logoutUrl("/logout"));
}