-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent logout before webview login (#1013)
* Prevent logout before webview login * Fix dispatch argument
- Loading branch information
1 parent
c930ac1
commit b9a98e5
Showing
3 changed files
with
163 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 15 additions & 15 deletions
30
src/services/nativeAuth/helpers/loginWithNativeAuthToken.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 })); | ||
} | ||
} |
Oops, something went wrong.