File tree 3 files changed +32
-4
lines changed
3 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import Acls from "./components/users/Acls";
15
15
import About from "./components/About" ;
16
16
import { useAppDispatch } from "./store" ;
17
17
import { fetchOcVersion , fetchUserInfo } from "./slices/userInfoSlice" ;
18
+ import { subscribeToAuthEvents } from "./utils/broadcastSync" ;
18
19
19
20
function App ( ) {
20
21
const dispatch = useAppDispatch ( ) ;
@@ -24,6 +25,9 @@ function App() {
24
25
// Load information about current opencast version on mount
25
26
dispatch ( fetchOcVersion ( ) ) ;
26
27
28
+ // Subscribe to the auth event to follow the login - logout events!
29
+ subscribeToAuthEvents ( ) ;
30
+
27
31
// Add event listener for back button to check if we are still logged in
28
32
window . addEventListener ( "popstate" , function ( event ) {
29
33
dispatch ( fetchUserInfo ( ) ) ;
Original file line number Diff line number Diff line change @@ -24,17 +24,14 @@ import { HiTranslate } from "react-icons/hi";
24
24
import { IconContext } from "react-icons" ;
25
25
import ButtonLikeAnchor from "./shared/ButtonLikeAnchor" ;
26
26
import { ModalHandle } from "./shared/modals/Modal" ;
27
+ import { broadcastLogout } from "../utils/broadcastSync" ;
27
28
28
29
// References for detecting a click outside of the container of the dropdown menus
29
30
const containerLang = React . createRef < HTMLDivElement > ( ) ;
30
31
const containerHelp = React . createRef < HTMLDivElement > ( ) ;
31
32
const containerUser = React . createRef < HTMLDivElement > ( ) ;
32
33
const containerNotify = React . createRef < HTMLDivElement > ( ) ;
33
34
34
- function logout ( ) {
35
- window . location . href = "/j_spring_security_logout" ;
36
- }
37
-
38
35
/**
39
36
* Component that renders the header and the navigation in the upper right corner.
40
37
*/
@@ -417,6 +414,12 @@ const MenuHelp = ({
417
414
418
415
const MenuUser = ( ) => {
419
416
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
+ }
420
423
return (
421
424
< ul className = "dropdown-ul" >
422
425
< 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