mirror of
https://github.com/danog/telegram-tt.git
synced 2024-11-30 04:39:00 +01:00
Fix infinite redirect to Auth screen
This commit is contained in:
parent
fe8f147a59
commit
c3318d93e6
@ -94,6 +94,7 @@ export async function init(_onUpdate: OnApiUpdate, initialArgs: ApiInitialArgs)
|
||||
qrCode: onRequestQrCode,
|
||||
onError: onAuthError,
|
||||
initialMethod: platform === 'iOS' || platform === 'Android' ? 'phoneNumber' : 'qrCode',
|
||||
shouldThrowIfUnauthorized: Boolean(sessionData),
|
||||
});
|
||||
} catch (err: any) {
|
||||
// eslint-disable-next-line no-console
|
||||
|
@ -836,7 +836,7 @@ class TelegramClient {
|
||||
await this.connect();
|
||||
}
|
||||
|
||||
if (await checkAuthorization(this)) {
|
||||
if (await checkAuthorization(this, authParams.shouldThrowIfUnauthorized)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ export interface UserAuthParams {
|
||||
onError: (err: Error) => void;
|
||||
forceSMS?: boolean;
|
||||
initialMethod?: 'phoneNumber' | 'qrCode';
|
||||
shouldThrowIfUnauthorized?: boolean;
|
||||
}
|
||||
|
||||
export interface BotAuthParams {
|
||||
@ -49,12 +50,12 @@ export async function authFlow(
|
||||
client._log.info('Signed in successfully as', utils.getDisplayName(me));
|
||||
}
|
||||
|
||||
export async function checkAuthorization(client: TelegramClient) {
|
||||
export async function checkAuthorization(client: TelegramClient, shouldThrow = false) {
|
||||
try {
|
||||
await client.invoke(new Api.updates.GetState());
|
||||
return true;
|
||||
} catch (e: any) {
|
||||
if (e.message === 'Disconnect') throw e;
|
||||
if (e.message === 'Disconnect' || shouldThrow) throw e;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user