Skip to content

Commit

Permalink
Fixed cross window page reload on internal logout] (#1350)
Browse files Browse the repository at this point in the history
  • Loading branch information
razvantomegea authored Dec 17, 2024
1 parent 9302e88 commit 1f4563a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- [Fixed cross window page reload on internal logout](https://github.com/multiversx/mx-sdk-dapp/pull/1350)

## [[v3.1.4](https://github.com/multiversx/mx-sdk-dapp/pull/1349)] - 2024-12-16

- [Fixed logout doesn't work when `shouldBroadcastLogoutAcrossTabs` is `false`](https://github.com/multiversx/mx-sdk-dapp/pull/1348)
Expand Down
9 changes: 7 additions & 2 deletions src/utils/logout.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { safeWindow } from 'lib/sdkDappUtils';
import { CrossWindowProvider } from 'lib/sdkWebWalletCrossWindowProvider';
import { getAccountProvider, getProviderType } from 'providers';
import { logoutAction } from 'reduxStore/commonActions';
Expand Down Expand Up @@ -70,13 +71,17 @@ export async function logout(

const url = addOriginToLocationPath(callbackUrl);
const location = getWindowLocation();
const callbackPathname = new URL(decodeURIComponent(url)).pathname;
const { pathname: callbackPathname, origin: callbackOrigin } = new URL(
decodeURIComponent(url)
);

// Prevent page redirect if the logout callbackURL is equal to the current URL
// or if is wallet provider
// or if we are in a child tab (redirects via window.assign cause automatic tab close)
if (
matchPath(location.pathname, callbackPathname) ||
(isWalletProvider && isProviderInitialised)
(isWalletProvider && isProviderInitialised) ||
(safeWindow?.opener && callbackOrigin === safeWindow?.origin)
) {
preventRedirects();
}
Expand Down

0 comments on commit 1f4563a

Please sign in to comment.