Skip to content

Commit

Permalink
Fix clear initiated login (#1301)
Browse files Browse the repository at this point in the history
* Fix clear initiated login

* Update CHANGELOG.md
  • Loading branch information
DanutIlie authored Nov 6, 2024
1 parent b370e9f commit 532e7b7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- [Fix clear initiated login](https://github.com/multiversx/mx-sdk-dapp/pull/1301)

## [[v3.0.8](https://github.com/multiversx/mx-sdk-dapp/pull/1299)] - 2024-11-04

- [Update skip method to clear only initiated login state](https://github.com/multiversx/mx-sdk-dapp/pull/1298)

- [Updated Iframe provider imports](https://github.com/multiversx/mx-sdk-dapp/pull/1297)
- [Fixed Iframe provider reload](https://github.com/multiversx/mx-sdk-dapp/pull/1295)

Expand Down
28 changes: 19 additions & 9 deletions src/hooks/login/helpers/clearInitiatedLogins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,29 @@ import { IframeProvider } from 'lib/sdkWebWalletIframeProvider';
import { LoginMethodsEnum } from 'types';

export const clearInitiatedLogins = (props?: {
intiatedLoginMethod: LoginMethodsEnum;
skipLoginMethod: LoginMethodsEnum;
}) => {
Object.values(LoginMethodsEnum).forEach((method) => {
if (props?.intiatedLoginMethod && method !== props.intiatedLoginMethod) {
if (method === props?.skipLoginMethod) {
return;
}
const crossWindowProvider = CrossWindowProvider.getInstance();
if (crossWindowProvider.isInitialized()) {
crossWindowProvider.dispose();
}
const iframeProvider = IframeProvider.getInstance();
if (iframeProvider.isInitialized()) {
iframeProvider.dispose();
switch (method) {
case LoginMethodsEnum.crossWindow: {
const crossWindowProvider = CrossWindowProvider.getInstance();
if (crossWindowProvider.isInitialized()) {
crossWindowProvider.dispose();
}
break;
}
case LoginMethodsEnum.iframe: {
const iframeProvider = IframeProvider.getInstance();
if (iframeProvider.isInitialized()) {
iframeProvider.dispose();
}
break;
}
default:
break;
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/login/useCrossWindowLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const useCrossWindowLogin = ({
}

clearInitiatedLogins({
intiatedLoginMethod: LoginMethodsEnum.crossWindow
skipLoginMethod: LoginMethodsEnum.crossWindow
});

setIsLoading(true);
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/login/useIframeLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const useIframeLogin = ({
}

clearInitiatedLogins({
intiatedLoginMethod: LoginMethodsEnum.iframe
skipLoginMethod: LoginMethodsEnum.iframe
});

setIsLoading(true);
Expand Down

0 comments on commit 532e7b7

Please sign in to comment.