Revert "Fix Web Token login (again) (#2137)"
This reverts commit 1a87b3cd539030e0a9646fae30f314c71254f6ed.
This commit is contained in:
parent
56bbb59e37
commit
9a9ea40166
@ -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);
|
||||
|
||||
@ -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<string>((resolve) => {
|
||||
|
||||
@ -61,7 +61,6 @@ export type ApiUpdateAuthorizationState = {
|
||||
authorizationState: ApiUpdateAuthorizationStateType;
|
||||
isCodeViaApp?: boolean;
|
||||
hint?: string;
|
||||
noReset?: boolean;
|
||||
qrCode?: { token: string; expires: number };
|
||||
};
|
||||
|
||||
|
||||
@ -24,21 +24,21 @@ type OwnProps = {
|
||||
isActive: boolean;
|
||||
};
|
||||
|
||||
type StateProps = Pick<GlobalState, 'authState' | 'hasWebAuthTokenPasswordRequired'>;
|
||||
type StateProps = Pick<GlobalState, 'authState'>;
|
||||
|
||||
const Auth: FC<OwnProps & StateProps> = ({
|
||||
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<OwnProps & StateProps> = ({
|
||||
};
|
||||
|
||||
export default memo(withGlobal<OwnProps>(
|
||||
(global): StateProps => pick(global, ['authState', 'hasWebAuthTokenPasswordRequired']),
|
||||
(global): StateProps => pick(global, ['authState']),
|
||||
)(Auth));
|
||||
|
||||
@ -114,7 +114,6 @@ function onUpdateAuthorizationState(update: ApiUpdateAuthorizationState) {
|
||||
setGlobal({
|
||||
...global,
|
||||
authHint: update.hint,
|
||||
hasWebAuthTokenPasswordRequired: update.noReset,
|
||||
});
|
||||
break;
|
||||
case 'authorizationStateWaitQrCode':
|
||||
|
||||
@ -141,7 +141,6 @@ export type GlobalState = {
|
||||
appConfig?: ApiAppConfig;
|
||||
canInstall?: boolean;
|
||||
hasWebAuthTokenFailed?: boolean;
|
||||
hasWebAuthTokenPasswordRequired?: boolean;
|
||||
isChatInfoShown: boolean;
|
||||
isStatisticsShown?: boolean;
|
||||
isLeftColumnShown: boolean;
|
||||
|
||||
@ -6,9 +6,9 @@ import { computeCheck as computePasswordSrpCheck } from '../Password';
|
||||
|
||||
export interface UserAuthParams {
|
||||
phoneNumber: string | (() => Promise<string>);
|
||||
webAuthTokenFailed: () => void;
|
||||
webAuthTokenFailed: VoidFunction;
|
||||
phoneCode: (isCodeViaApp?: boolean) => Promise<string>;
|
||||
password: (hint?: string, noReset?: boolean) => Promise<string>;
|
||||
password: (hint?: string) => Promise<string>;
|
||||
firstAndLastNames: () => Promise<[string, string?]>;
|
||||
qrCode: (qrCode: { token: Buffer; expires: number }) => Promise<void>;
|
||||
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<Api.TypeUser> {
|
||||
// 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');
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user