mirror of
https://github.com/danog/telegram-tt.git
synced 2024-12-03 18:17:59 +01:00
Auth: Default to phone number auth on mobiles
This commit is contained in:
parent
2dcaa804e2
commit
58b984aaa0
@ -44,7 +44,7 @@ export async function init(_onUpdate: OnApiUpdate, initialArgs: ApiInitialArgs)
|
|||||||
|
|
||||||
onUpdate = _onUpdate;
|
onUpdate = _onUpdate;
|
||||||
|
|
||||||
const { sessionData, userAgent } = initialArgs;
|
const { userAgent, platform, sessionData } = initialArgs;
|
||||||
const session = new sessions.CallbackSession(sessionData, onSessionUpdate);
|
const session = new sessions.CallbackSession(sessionData, onSessionUpdate);
|
||||||
|
|
||||||
client = new TelegramClient(
|
client = new TelegramClient(
|
||||||
@ -76,7 +76,7 @@ export async function init(_onUpdate: OnApiUpdate, initialArgs: ApiInitialArgs)
|
|||||||
firstAndLastNames: onRequestRegistration,
|
firstAndLastNames: onRequestRegistration,
|
||||||
qrCode: onRequestQrCode,
|
qrCode: onRequestQrCode,
|
||||||
onError: onAuthError,
|
onError: onAuthError,
|
||||||
initialMethod: 'qrCode',
|
initialMethod: platform === 'iOS' || platform === 'Android' ? 'phoneNumber' : 'qrCode',
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
onUpdate({
|
onUpdate({
|
||||||
|
@ -2,6 +2,7 @@ import { ApiDocument } from './messages';
|
|||||||
|
|
||||||
export interface ApiInitialArgs {
|
export interface ApiInitialArgs {
|
||||||
userAgent: string;
|
userAgent: string;
|
||||||
|
platform?: string;
|
||||||
sessionData?: ApiSessionData;
|
sessionData?: ApiSessionData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ import AuthRegister from './AuthRegister.async';
|
|||||||
import AuthQrCode from './AuthQrCode';
|
import AuthQrCode from './AuthQrCode';
|
||||||
|
|
||||||
import './Auth.scss';
|
import './Auth.scss';
|
||||||
|
import { PLATFORM_ENV } from '../../util/environment';
|
||||||
|
|
||||||
type StateProps = Pick<GlobalState, 'authState'>;
|
type StateProps = Pick<GlobalState, 'authState'>;
|
||||||
type DispatchProps = Pick<GlobalActions, 'reset' | 'initApi'>;
|
type DispatchProps = Pick<GlobalActions, 'reset' | 'initApi'>;
|
||||||
@ -35,7 +36,9 @@ const Auth: FC<StateProps & DispatchProps> = ({ authState, reset, initApi }) =>
|
|||||||
return <UiLoader page="authPhoneNumber" key="authPhoneNumber"><AuthPhoneNumber /></UiLoader>;
|
return <UiLoader page="authPhoneNumber" key="authPhoneNumber"><AuthPhoneNumber /></UiLoader>;
|
||||||
case 'authorizationStateWaitQrCode':
|
case 'authorizationStateWaitQrCode':
|
||||||
default:
|
default:
|
||||||
return <UiLoader page="authQrCode" key="authQrCode"><AuthQrCode /></UiLoader>;
|
return PLATFORM_ENV === 'iOS' || PLATFORM_ENV === 'Android'
|
||||||
|
? <UiLoader page="authPhoneNumber" key="authPhoneNumber"><AuthPhoneNumber /></UiLoader>
|
||||||
|
: <UiLoader page="authQrCode" key="authQrCode"><AuthQrCode /></UiLoader>;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -11,13 +11,13 @@ import Loading from '../ui/Loading';
|
|||||||
import Button from '../ui/Button';
|
import Button from '../ui/Button';
|
||||||
import useHistoryBack from '../../hooks/useHistoryBack';
|
import useHistoryBack from '../../hooks/useHistoryBack';
|
||||||
|
|
||||||
type StateProps = Pick<GlobalState, 'connectionState' | 'authQrCode'>;
|
type StateProps = Pick<GlobalState, 'connectionState' | 'authState' | 'authQrCode'>;
|
||||||
type DispatchProps = Pick<GlobalActions, 'returnToAuthPhoneNumber'>;
|
type DispatchProps = Pick<GlobalActions, 'returnToAuthPhoneNumber'>;
|
||||||
|
|
||||||
const DATA_PREFIX = 'tg://login?token=';
|
const DATA_PREFIX = 'tg://login?token=';
|
||||||
|
|
||||||
const AuthCode: FC<StateProps & DispatchProps> = ({
|
const AuthCode: FC<StateProps & DispatchProps> = ({
|
||||||
connectionState, authQrCode, returnToAuthPhoneNumber,
|
connectionState, authState, authQrCode, returnToAuthPhoneNumber,
|
||||||
}) => {
|
}) => {
|
||||||
// eslint-disable-next-line no-null/no-null
|
// eslint-disable-next-line no-null/no-null
|
||||||
const qrCodeRef = useRef<HTMLDivElement>(null);
|
const qrCodeRef = useRef<HTMLDivElement>(null);
|
||||||
@ -43,6 +43,8 @@ const AuthCode: FC<StateProps & DispatchProps> = ({
|
|||||||
|
|
||||||
useHistoryBack(returnToAuthPhoneNumber);
|
useHistoryBack(returnToAuthPhoneNumber);
|
||||||
|
|
||||||
|
const isAuthReady = authState === 'authorizationStateWaitQrCode';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div id="auth-qr-form" className="custom-scroll">
|
<div id="auth-qr-form" className="custom-scroll">
|
||||||
<div className="auth-form qr">
|
<div className="auth-form qr">
|
||||||
@ -57,13 +59,15 @@ const AuthCode: FC<StateProps & DispatchProps> = ({
|
|||||||
<li><span>Go to <b>Settings</b> > <b>Devices</b> > <b>Scan QR</b></span></li>
|
<li><span>Go to <b>Settings</b> > <b>Devices</b> > <b>Scan QR</b></span></li>
|
||||||
<li><span>Point your phone at this screen to confirm login</span></li>
|
<li><span>Point your phone at this screen to confirm login</span></li>
|
||||||
</ol>
|
</ol>
|
||||||
<Button isText onClick={returnToAuthPhoneNumber}>Log in by phone number</Button>
|
{isAuthReady && (
|
||||||
|
<Button isText onClick={returnToAuthPhoneNumber}>Log in by phone number</Button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default memo(withGlobal(
|
export default memo(withGlobal(
|
||||||
(global): StateProps => pick(global, ['connectionState', 'authQrCode']),
|
(global): StateProps => pick(global, ['connectionState', 'authState', 'authQrCode']),
|
||||||
(setGlobal, actions): DispatchProps => pick(actions, ['returnToAuthPhoneNumber']),
|
(setGlobal, actions): DispatchProps => pick(actions, ['returnToAuthPhoneNumber']),
|
||||||
)(AuthCode));
|
)(AuthCode));
|
||||||
|
@ -12,6 +12,7 @@ import {
|
|||||||
MEDIA_PROGRESSIVE_CACHE_NAME,
|
MEDIA_PROGRESSIVE_CACHE_NAME,
|
||||||
IS_TEST,
|
IS_TEST,
|
||||||
} from '../../../config';
|
} from '../../../config';
|
||||||
|
import { PLATFORM_ENV } from '../../../util/environment';
|
||||||
import { initApi, callApi } from '../../../api/gramjs';
|
import { initApi, callApi } from '../../../api/gramjs';
|
||||||
import { unsubscribe } from '../../../util/notifications';
|
import { unsubscribe } from '../../../util/notifications';
|
||||||
import * as cacheApi from '../../../util/cacheApi';
|
import * as cacheApi from '../../../util/cacheApi';
|
||||||
@ -33,6 +34,7 @@ addReducer('initApi', (global: GlobalState, actions) => {
|
|||||||
|
|
||||||
void initApi(actions.apiUpdate, {
|
void initApi(actions.apiUpdate, {
|
||||||
userAgent: navigator.userAgent,
|
userAgent: navigator.userAgent,
|
||||||
|
platform: PLATFORM_ENV,
|
||||||
sessionData: loadStoredSession(),
|
sessionData: loadStoredSession(),
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
@ -15,10 +15,10 @@ export function getPlatform() {
|
|||||||
const macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'];
|
const macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'];
|
||||||
const windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'];
|
const windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'];
|
||||||
const iosPlatforms = ['iPhone', 'iPad', 'iPod'];
|
const iosPlatforms = ['iPhone', 'iPad', 'iPod'];
|
||||||
let os: 'Mac OS' | 'iOS' | 'Windows' | 'Android' | 'Linux' | undefined;
|
let os: 'macOS' | 'iOS' | 'Windows' | 'Android' | 'Linux' | undefined;
|
||||||
|
|
||||||
if (macosPlatforms.indexOf(platform) !== -1) {
|
if (macosPlatforms.indexOf(platform) !== -1) {
|
||||||
os = 'Mac OS';
|
os = 'macOS';
|
||||||
} else if (iosPlatforms.indexOf(platform) !== -1) {
|
} else if (iosPlatforms.indexOf(platform) !== -1) {
|
||||||
os = 'iOS';
|
os = 'iOS';
|
||||||
} else if (windowsPlatforms.indexOf(platform) !== -1) {
|
} else if (windowsPlatforms.indexOf(platform) !== -1) {
|
||||||
@ -33,7 +33,7 @@ export function getPlatform() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const PLATFORM_ENV = getPlatform();
|
export const PLATFORM_ENV = getPlatform();
|
||||||
export const IS_MAC_OS = PLATFORM_ENV === 'Mac OS';
|
export const IS_MAC_OS = PLATFORM_ENV === 'macOS';
|
||||||
export const IS_IOS = PLATFORM_ENV === 'iOS';
|
export const IS_IOS = PLATFORM_ENV === 'iOS';
|
||||||
export const IS_ANDROID = PLATFORM_ENV === 'Android';
|
export const IS_ANDROID = PLATFORM_ENV === 'Android';
|
||||||
export const IS_SAFARI = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
export const IS_SAFARI = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
||||||
|
Loading…
Reference in New Issue
Block a user