feat(core): onQrScanned callback in signInQr

This commit is contained in:
alina 🌸 2024-07-01 20:27:47 +03:00
parent 0290bb429a
commit e432fdb5b3
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
2 changed files with 14 additions and 1 deletions

View file

@ -729,6 +729,12 @@ export interface TelegramClient extends ITelegramClient {
*/ */
onUrlUpdated: (url: string, expires: Date) => void 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 for 2FA */
password?: MaybeDynamic<string> password?: MaybeDynamic<string>

View file

@ -27,6 +27,12 @@ export async function signInQr(
*/ */
onUrlUpdated: (url: string, expires: Date) => void 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 for 2FA */
password?: MaybeDynamic<string> password?: MaybeDynamic<string>
@ -42,7 +48,7 @@ export async function signInQr(
abortSignal?: AbortSignal abortSignal?: AbortSignal
}, },
): Promise<User> { ): Promise<User> {
const { onUrlUpdated, abortSignal } = params const { onUrlUpdated, abortSignal, onQrScanned } = params
let waiter: ControllablePromise<void> | undefined let waiter: ControllablePromise<void> | undefined
@ -56,6 +62,7 @@ export async function signInQr(
const onUpdate: ServerUpdateHandler = (upd) => { const onUpdate: ServerUpdateHandler = (upd) => {
if (upd._ === 'updateShort' && upd.update._ === 'updateLoginToken') { if (upd._ === 'updateShort' && upd.update._ === 'updateLoginToken') {
onQrScanned?.()
waiter?.resolve() waiter?.resolve()
client.onServerUpdate(originalHandler) client.onServerUpdate(originalHandler)
} }