You're almost there! Please answer a few more questions for access to the Applications content. Complete registration
Interested in joining? Complete your registration by providing Areas of Interest here. Register

We need to trigger 'Logout' action when user closes storefront window or tab.

Summary:

We need to trigger 'Logout' action when user closes window or tab. When using event listener for 'beforeunload' event, the listener function executes but doesnt trigger the required actions.

Code Snippet (add any code snippets that support your topic, if applicable):

useEffect(() => {

const closeTabsEventListener = (event) => {   

event.preventDefault();    action('logout'); 

};

window.addEventListener('beforeunload', closeTabsEventListener);

}[]);

Howdy, Stranger!

Log In

To view full details, sign in.

Register

Don't have an account? Click here to get started!