Skip to content

Commit

Permalink
clear localstorage when session expires
Browse files Browse the repository at this point in the history
  • Loading branch information
ajayadav09 committed Oct 1, 2024
1 parent fda55d2 commit 9cf0230
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/components/HelpCenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ const HelpCenter = ( props ) => {
};
}, [] );

useEffect( () => {
const handleHeartbeat = ( event, data ) => {
if (
data.hasOwnProperty( 'wp-auth-check' ) &&
! data[ 'wp-auth-check' ]
) {
// WordPress auth check failed, session is expired, Clear relevant localStorage data
LocalStorageUtils.clear();
}
};

// Listening to the WordPress Heartbeat tick event to check user session
window.jQuery( document ).on( 'heartbeat-tick', handleHeartbeat );

return () => {
window.jQuery( document ).off( 'heartbeat-tick', handleHeartbeat );
};
}, [] );

if ( ! helpEnabled || ! visible ) {
return <></>;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ResultContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const ResultContent = ( {
content.length > 0
);
}
console.log( 'is no result:', noResult, 'is new entry:', isNewEntry );

return (
<>
<div ref={ responseRef } className="helpcenter-response-block">
Expand Down

0 comments on commit 9cf0230

Please sign in to comment.