import { useEffect } from 'react' ; import { getIsSelf , getMessage , PASSWORD_CHANGE_MESSAGE_TYPE } from '@proton/shared/lib/helpers/crossTab' ; import { useAuthentication } from '../../hooks' ; const StorageListener = ( ) => { const authentication = useAuthentication ( ) ; useEffect ( ( ) => { const cb = ( e ) => { const message = getMessage ( e ) ; if ( ! message ) { return ; } const { id , type , data } = message ; if ( type === PASSWORD_CHANGE_MESSAGE_TYPE && data ?. localID === authentication . getLocalID ?. ( ) && ! getIsSelf ( id ) ) { authentication . logout ( 'soft' ) ; } } ; window . addEventListener ( 'storage' , cb ) ; return ( ) => { window . removeEventListener ( 'storage' , cb ) ; } ; } , [ ] ) ; return < > { null } < />; } ; export default StorageListener ;