From e432fdb5b3f0c483b1c1f7596f128aeb940ca671 Mon Sep 17 00:00:00 2001 From: alina sireneva Date: Mon, 1 Jul 2024 20:27:47 +0300 Subject: [PATCH] feat(core): onQrScanned callback in signInQr --- packages/core/src/highlevel/client.ts | 6 ++++++ packages/core/src/highlevel/methods/auth/sign-in-qr.ts | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/core/src/highlevel/client.ts b/packages/core/src/highlevel/client.ts index bd70098b..ceddd3c2 100644 --- a/packages/core/src/highlevel/client.ts +++ b/packages/core/src/highlevel/client.ts @@ -729,6 +729,12 @@ export interface TelegramClient extends ITelegramClient { */ onUrlUpdated: (url: string, expires: Date) => void + /** + * Function that will be called when the user has scanned the QR code + * (i.e. when `updateLoginToken` is received), and the library is finalizing the auth + */ + onQrScanned?: () => void + /** Password for 2FA */ password?: MaybeDynamic diff --git a/packages/core/src/highlevel/methods/auth/sign-in-qr.ts b/packages/core/src/highlevel/methods/auth/sign-in-qr.ts index 07ef3498..0b9a1637 100644 --- a/packages/core/src/highlevel/methods/auth/sign-in-qr.ts +++ b/packages/core/src/highlevel/methods/auth/sign-in-qr.ts @@ -27,6 +27,12 @@ export async function signInQr( */ onUrlUpdated: (url: string, expires: Date) => void + /** + * Function that will be called when the user has scanned the QR code + * (i.e. when `updateLoginToken` is received), and the library is finalizing the auth + */ + onQrScanned?: () => void + /** Password for 2FA */ password?: MaybeDynamic @@ -42,7 +48,7 @@ export async function signInQr( abortSignal?: AbortSignal }, ): Promise { - const { onUrlUpdated, abortSignal } = params + const { onUrlUpdated, abortSignal, onQrScanned } = params let waiter: ControllablePromise | undefined @@ -56,6 +62,7 @@ export async function signInQr( const onUpdate: ServerUpdateHandler = (upd) => { if (upd._ === 'updateShort' && upd.update._ === 'updateLoginToken') { + onQrScanned?.() waiter?.resolve() client.onServerUpdate(originalHandler) }