diff --git a/src/App.tsx b/src/App.tsx index cb4ddfaff..393346f4b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -181,7 +181,7 @@ export default withGlobal( authState: global.authState, isScreenLocked: global.passcode?.isScreenLocked, hasPasscode: global.passcode?.hasPasscode, - hasWebAuthTokenFailed: global.hasWebAuthTokenFailed || global.hasWebAuthTokenPasswordRequired, + hasWebAuthTokenFailed: global.hasWebAuthTokenFailed, }; }, )(App); diff --git a/src/api/gramjs/methods/auth.ts b/src/api/gramjs/methods/auth.ts index 9f1b6847f..c540fecc3 100644 --- a/src/api/gramjs/methods/auth.ts +++ b/src/api/gramjs/methods/auth.ts @@ -54,11 +54,10 @@ export function onRequestCode(isCodeViaApp = false) { }); } -export function onRequestPassword(hint?: string, noReset?: boolean) { +export function onRequestPassword(hint?: string) { onUpdate({ ...buildAuthStateUpdate('authorizationStateWaitPassword'), hint, - noReset, }); return new Promise((resolve) => { diff --git a/src/api/types/updates.ts b/src/api/types/updates.ts index a79b3ce1d..244ed5f66 100644 --- a/src/api/types/updates.ts +++ b/src/api/types/updates.ts @@ -61,7 +61,6 @@ export type ApiUpdateAuthorizationState = { authorizationState: ApiUpdateAuthorizationStateType; isCodeViaApp?: boolean; hint?: string; - noReset?: boolean; qrCode?: { token: string; expires: number }; }; diff --git a/src/components/auth/Auth.tsx b/src/components/auth/Auth.tsx index 354e65a30..bec4418e3 100644 --- a/src/components/auth/Auth.tsx +++ b/src/components/auth/Auth.tsx @@ -24,21 +24,21 @@ type OwnProps = { isActive: boolean; }; -type StateProps = Pick; +type StateProps = Pick; const Auth: FC = ({ - isActive, authState, hasWebAuthTokenPasswordRequired, + isActive, authState, }) => { const { reset, initApi, returnToAuthPhoneNumber, goToAuthQrCode, } = getActions(); useEffect(() => { - if (isActive && !hasWebAuthTokenPasswordRequired) { + if (isActive) { reset(); initApi(); } - }, [isActive, reset, initApi, hasWebAuthTokenPasswordRequired]); + }, [isActive, reset, initApi]); const isMobile = PLATFORM_ENV === 'iOS' || PLATFORM_ENV === 'Android'; @@ -113,5 +113,5 @@ const Auth: FC = ({ }; export default memo(withGlobal( - (global): StateProps => pick(global, ['authState', 'hasWebAuthTokenPasswordRequired']), + (global): StateProps => pick(global, ['authState']), )(Auth)); diff --git a/src/global/actions/apiUpdaters/initial.ts b/src/global/actions/apiUpdaters/initial.ts index 296f64cbd..742a34bb6 100644 --- a/src/global/actions/apiUpdaters/initial.ts +++ b/src/global/actions/apiUpdaters/initial.ts @@ -114,7 +114,6 @@ function onUpdateAuthorizationState(update: ApiUpdateAuthorizationState) { setGlobal({ ...global, authHint: update.hint, - hasWebAuthTokenPasswordRequired: update.noReset, }); break; case 'authorizationStateWaitQrCode': diff --git a/src/global/types.ts b/src/global/types.ts index f34d5815f..3e20f8f9c 100644 --- a/src/global/types.ts +++ b/src/global/types.ts @@ -141,7 +141,6 @@ export type GlobalState = { appConfig?: ApiAppConfig; canInstall?: boolean; hasWebAuthTokenFailed?: boolean; - hasWebAuthTokenPasswordRequired?: boolean; isChatInfoShown: boolean; isStatisticsShown?: boolean; isLeftColumnShown: boolean; diff --git a/src/lib/gramjs/client/auth.ts b/src/lib/gramjs/client/auth.ts index ecb7d17be..c7aae74df 100644 --- a/src/lib/gramjs/client/auth.ts +++ b/src/lib/gramjs/client/auth.ts @@ -6,9 +6,9 @@ import { computeCheck as computePasswordSrpCheck } from '../Password'; export interface UserAuthParams { phoneNumber: string | (() => Promise); - webAuthTokenFailed: () => void; + webAuthTokenFailed: VoidFunction; phoneCode: (isCodeViaApp?: boolean) => Promise; - password: (hint?: string, noReset?: boolean) => Promise; + password: (hint?: string) => Promise; firstAndLastNames: () => Promise<[string, string?]>; qrCode: (qrCode: { token: Buffer; expires: number }) => Promise; onError: (err: Error) => void; @@ -87,11 +87,11 @@ async function signInUserWithWebToken( throw new Error('SIGN_UP_REQUIRED'); } } catch (err: any) { + authParams.webAuthTokenFailed(); + client._log.error(`Failed to login with web token: ${err}`); if (err.message === 'SESSION_PASSWORD_NEEDED') { - return signInWithPassword(client, apiCredentials, authParams, true); + return signInWithPassword(client, apiCredentials, authParams); } else { - client._log.error(`Failed to login with web token: ${err}`); - authParams.webAuthTokenFailed(); return signInUserWithPreferredMethod(client, apiCredentials, { ...authParams, webAuthToken: undefined, @@ -344,13 +344,13 @@ async function sendCode( } async function signInWithPassword( - client: TelegramClient, apiCredentials: ApiCredentials, authParams: UserAuthParams, noReset = false, + client: TelegramClient, apiCredentials: ApiCredentials, authParams: UserAuthParams, ): Promise { // eslint-disable-next-line no-constant-condition while (1) { try { const passwordSrpResult = await client.invoke(new Api.account.GetPassword()); - const password = await authParams.password(passwordSrpResult.hint, noReset); + const password = await authParams.password(passwordSrpResult.hint); if (!password) { throw new Error('Password is empty'); }