ADD logout functionality to SecurityConfig and Topbar
This commit is contained in:
@@ -13,6 +13,7 @@ type props = {
|
||||
const Topbar = ({sidebarToggled, setSidebarToggled, user, className}: props) => {
|
||||
const apiUrl = import.meta.env.VITE_API_URL;
|
||||
const loginUrl = `${apiUrl}/oauth2/authorization/google`;
|
||||
const logoutUrl = `${apiUrl}/api/v1/auth/logout`;
|
||||
|
||||
return (
|
||||
<div className={clsx(className, "flex justify-between")}>
|
||||
@@ -20,10 +21,24 @@ const Topbar = ({sidebarToggled, setSidebarToggled, user, className}: props) =>
|
||||
{sidebarToggled ? <Menu size={24}/> : <X size={24}/>}
|
||||
</MenuButton>
|
||||
|
||||
<MenuButton className={"w-40 text-gray-600"}
|
||||
onClick={() => globalThis.location.href = loginUrl}>
|
||||
{ user ? user.name : "Login" }
|
||||
</MenuButton>
|
||||
{ user ? (
|
||||
<div>
|
||||
<MenuButton className={"w-40 text-gray-600"}>
|
||||
{user.name}
|
||||
</MenuButton>
|
||||
<MenuButton className={"w-20 text-gray-600"}
|
||||
onClick={() => globalThis.location.href = logoutUrl}>
|
||||
Logout
|
||||
</MenuButton>
|
||||
</div>
|
||||
) :
|
||||
(
|
||||
<MenuButton className={"w-20 text-gray-600"}
|
||||
onClick={() => globalThis.location.href = loginUrl}>
|
||||
Login
|
||||
</MenuButton>
|
||||
)};
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.springframework.security.config.annotation.web.configuration.EnableWe
|
||||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
|
||||
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
@@ -41,7 +42,9 @@ public class SecurityConfig {
|
||||
.successHandler(successHandler()))
|
||||
.logout(logout -> logout
|
||||
.logoutUrl("/api/v1/auth/logout")
|
||||
.logoutSuccessUrl(frontendUrl)
|
||||
.logoutSuccessHandler(logoutSuccessHandler())
|
||||
.invalidateHttpSession(true)
|
||||
.deleteCookies("JSESSIONID")
|
||||
);
|
||||
|
||||
return http.build();
|
||||
@@ -52,4 +55,9 @@ public class SecurityConfig {
|
||||
return (request, response, authentication) -> response.sendRedirect(frontendUrl);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public LogoutSuccessHandler logoutSuccessHandler() {
|
||||
return (request, response, authentication) -> response.sendRedirect(frontendUrl);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user