Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(applock): prevent unintentional logout when applock is active [15545] #18698

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/script/page/AppLock/AppLock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ const AppLock: React.FC<AppLockProps> = ({
'isAppLockEnforced',
]);

// We log the user out if there is a style change on the app element
// i.e. if there is an attempt to remove the blur effect
const {current: appObserver} = useRef(
new MutationObserver(mutationRecords => {
const [{attributeName}] = mutationRecords;
Expand All @@ -93,6 +95,7 @@ const AppLock: React.FC<AppLockProps> = ({
}),
);

// We log the user out if the modal is removed from the DOM
const {current: modalObserver} = useRef(
new MutationObserver(() => {
const modalInDOM = document.querySelector('[data-uie-name="applock-modal"]');
Expand Down Expand Up @@ -156,11 +159,16 @@ const AppLock: React.FC<AppLockProps> = ({
app?.style.setProperty('pointer-events', isVisible ? 'none' : 'auto', 'important');

if (isVisible) {
modalObserver.observe(document.querySelector('#wire-main'), {
childList: true,
subtree: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was unable to pinpoint the exact cause, but this observer was checking for both childList and subtree for a removal attempt of the modal.
It doesn't seem to be necessary to include the subtree with our current code structure, as the app correctly logs out when removing the app lock modal from the DOM

});
appObserver.observe(document.querySelector('#app'), {attributes: true});
const wireMain = document.querySelector('#wire-main');
if (wireMain) {
modalObserver.observe(wireMain, {
childList: true,
});
}
const appElement = document.querySelector('#app');
if (appElement) {
appObserver.observe(appElement, {attributes: true});
}
}
return () => {
modalObserver.disconnect();
Expand Down
Loading