diff --git a/frontend/src/components/Topbar.tsx b/frontend/src/components/Topbar.tsx index 13700d8..4357cbf 100644 --- a/frontend/src/components/Topbar.tsx +++ b/frontend/src/components/Topbar.tsx @@ -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 (
@@ -20,10 +21,24 @@ const Topbar = ({sidebarToggled, setSidebarToggled, user, className}: props) => {sidebarToggled ? : } - globalThis.location.href = loginUrl}> - { user ? user.name : "Login" } - + { user ? ( +
+ + {user.name} + + globalThis.location.href = logoutUrl}> + Logout + +
+ ) : + ( + globalThis.location.href = loginUrl}> + Login + + )}; +
) } diff --git a/src/main/java/com/ddf/vodsystem/configuration/SecurityConfig.java b/src/main/java/com/ddf/vodsystem/configuration/SecurityConfig.java index 790512e..d7d8d04 100644 --- a/src/main/java/com/ddf/vodsystem/configuration/SecurityConfig.java +++ b/src/main/java/com/ddf/vodsystem/configuration/SecurityConfig.java @@ -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); + } + } \ No newline at end of file