File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import Acls from "./components/users/Acls";
1515import About from "./components/About" ;
1616import { useAppDispatch } from "./store" ;
1717import { fetchOcVersion , fetchUserInfo } from "./slices/userInfoSlice" ;
18+ import { subscribeToAuthEvents } from "./utils/broadcastSync" ;
1819
1920function App ( ) {
2021 const dispatch = useAppDispatch ( ) ;
@@ -24,6 +25,9 @@ function App() {
2425 // Load information about current opencast version on mount
2526 dispatch ( fetchOcVersion ( ) ) ;
2627
28+ // Subscribe to the auth event to follow the login - logout events!
29+ subscribeToAuthEvents ( ) ;
30+
2731 // Add event listener for back button to check if we are still logged in
2832 window . addEventListener ( "popstate" , function ( event ) {
2933 dispatch ( fetchUserInfo ( ) ) ;
Original file line number Diff line number Diff line change @@ -24,17 +24,14 @@ import { HiTranslate } from "react-icons/hi";
2424import { IconContext } from "react-icons" ;
2525import ButtonLikeAnchor from "./shared/ButtonLikeAnchor" ;
2626import { ModalHandle } from "./shared/modals/Modal" ;
27+ import { broadcastLogout } from "../utils/broadcastSync" ;
2728
2829// References for detecting a click outside of the container of the dropdown menus
2930const containerLang = React . createRef < HTMLDivElement > ( ) ;
3031const containerHelp = React . createRef < HTMLDivElement > ( ) ;
3132const containerUser = React . createRef < HTMLDivElement > ( ) ;
3233const containerNotify = React . createRef < HTMLDivElement > ( ) ;
3334
34- function logout ( ) {
35- window . location . href = "/j_spring_security_logout" ;
36- }
37-
3835/**
3936 * Component that renders the header and the navigation in the upper right corner.
4037 */
@@ -417,6 +414,12 @@ const MenuHelp = ({
417414
418415const MenuUser = ( ) => {
419416 const { t } = useTranslation ( ) ;
417+
418+ const logout = ( ) => {
419+ // Here we broadcast logout, in order to redirect other tabs to login page!
420+ broadcastLogout ( ) ;
421+ window . location . href = "/j_spring_security_logout" ;
422+ }
420423 return (
421424 < ul className = "dropdown-ul" >
422425 < li >
Original file line number Diff line number Diff line change 1+ const bc = new BroadcastChannel ( 'auth_channel' ) ;
2+
3+ export const broadcastLogout = ( ) => {
4+ bc . postMessage ( { type : 'LOGOUT' } ) ;
5+ } ;
6+
7+ export const subscribeToAuthEvents = ( ) => {
8+ bc . onmessage = ( event ) => {
9+ if ( event . data ?. type === 'LOGOUT' ) {
10+ performOnLogoutActions ( ) ;
11+ }
12+ } ;
13+ } ;
14+
15+ const performOnLogoutActions = ( ) => {
16+ // We need a tiny pause, in order to make sure the logout process has happened.
17+ const intvl = setInterval ( ( ) => {
18+ window . location . href = "/login.html" ;
19+ clearInterval ( intvl ) ;
20+ } , 750 ) ;
21+ }
You can’t perform that action at this time.
0 commit comments