Skip to content

Commit

Permalink
Prevent logout before webview login (#1013)
Browse files Browse the repository at this point in the history
* Prevent logout before webview login

* Fix dispatch argument
  • Loading branch information
razvantomegea authored Jan 8, 2024
1 parent c930ac1 commit b9a98e5
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 155 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]

## [[v2.26.7]](https://github.com/multiversx/mx-sdk-dapp/pull/1013)] - 2024-01-08
- [Prevent logout before webview login](https://github.com/multiversx/mx-sdk-dapp/pull/1012)

## [[v2.26.6]](https://github.com/multiversx/mx-sdk-dapp/pull/1011)] - 2024-01-05
- [Add custom request option for WC button](https://github.com/multiversx/mx-sdk-dapp/pull/1010)
Expand Down
30 changes: 15 additions & 15 deletions src/services/nativeAuth/helpers/loginWithNativeAuthToken.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import { loginAction, logoutAction } from 'reduxStore/commonActions';
import { loginAction } from 'reduxStore/commonActions';
import { setTokenLogin } from 'reduxStore/slices';
import { store } from 'reduxStore/store';
import { LoginMethodsEnum } from 'types';
import { decodeNativeAuthToken } from './decodeNativeAuthToken';

export function loginWithNativeAuthToken(token: string, dispatch?: any) {
export function loginWithNativeAuthToken(
token: string,
dispatch = store.dispatch
) {
const nativeAuthInfo = decodeNativeAuthToken(token);

if (nativeAuthInfo == null) {
return;
}
const dispatchFn = dispatch ?? store.dispatch;

const { signature, address } = nativeAuthInfo;

if (signature && token && address) {
//this will clear out the store from all previous logins
dispatchFn(logoutAction());
dispatch(
setTokenLogin({
loginToken: token,
signature,
nativeAuthToken: token
})
);

setTimeout(() => {
dispatchFn(
setTokenLogin({
loginToken: token,
signature,
nativeAuthToken: token
})
);
dispatchFn(loginAction({ address, loginMethod: LoginMethodsEnum.extra }));
});
dispatch(loginAction({ address, loginMethod: LoginMethodsEnum.extra }));
}
}
Loading

0 comments on commit b9a98e5

Please sign in to comment.