From 6afb92765c688200e065acb337268439ed8bd3ee Mon Sep 17 00:00:00 2001 From: Razvan Tomegea Date: Thu, 4 Jan 2024 09:19:33 +0200 Subject: [PATCH] Prevent redirects on logout if the provider is both of wallet type and initialised (#1006) * Prevent redirects on logout if the provider is both of wallet type and initialised * 2.26.4 --- CHANGELOG.md | 3 +++ package.json | 2 +- src/utils/logout.ts | 10 +++++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fad480c7f..a903ab61f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [[v2.26.4]](https://github.com/multiversx/mx-sdk-dapp/pull/1007)] - 2024-01-04 +- [Prevent redirects on logout if the provider is both of wallet type and initialised](https://github.com/multiversx/mx-sdk-dapp/pull/1006) + ## [[v2.26.3]](https://github.com/multiversx/mx-sdk-dapp/pull/1005)] - 2024-01-03 - [Fix logout issue with web-wallet](https://github.com/multiversx/mx-sdk-dapp/pull/1004) diff --git a/package.json b/package.json index 36d3df1d6..010257e8d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@multiversx/sdk-dapp", - "version": "2.26.3", + "version": "2.26.4", "description": "A library to hold the main logic for a dapp on the MultiversX blockchain", "author": "MultiversX", "license": "GPL-3.0-or-later", diff --git a/src/utils/logout.ts b/src/utils/logout.ts index fc6784a22..e35435550 100644 --- a/src/utils/logout.ts +++ b/src/utils/logout.ts @@ -51,6 +51,7 @@ export async function logout( const provider = getAccountProvider(); const providerType = getProviderType(provider); const isWalletProvider = providerType === LoginMethodsEnum.wallet; + const isProviderInitialised = provider?.isInitialized?.() != null; if (shouldAttemptReLogin && provider?.relogin != null) { return provider.relogin(); @@ -69,12 +70,15 @@ export async function logout( // Prevent page redirect if the logout callbackURL is equal to the current URL // or if is wallet provider - if (matchPath(location.pathname, callbackPathname) || isWalletProvider) { + if ( + matchPath(location.pathname, callbackPathname) || + (isWalletProvider && isProviderInitialised) + ) { preventRedirects(); } // We are already logged out, so we can redirect to the dapp - if (!address && provider?.isInitialized?.() == null) { + if (!address && !isProviderInitialised) { return redirectToCallbackUrl({ callbackUrl: url, onRedirect @@ -84,7 +88,7 @@ export async function logout( try { store.dispatch(logoutAction()); - if (providerType === LoginMethodsEnum.wallet) { + if (isWalletProvider) { // Allow redux store cleanup before redirect to web wallet return setTimeout(() => { provider.logout({ callbackUrl: url });