This commit is contained in:
sdarbinyan
2026-04-14 23:14:26 +04:00
parent a15f2bca6a
commit 6e5fb3b86a
3 changed files with 78 additions and 1 deletions

View File

@@ -47,7 +47,11 @@ export class TelegramLoginComponent implements OnDestroy {
openTelegramLogin(): void {
window.open(this.loginUrl(), '_blank');
if (!this.pollTimer) {
this.startPolling(this.qrToken());
if (this.qrToken()) {
this.startPolling(this.qrToken());
} else {
this.startSessionPolling();
}
}
}
@@ -68,10 +72,30 @@ export class TelegramLoginComponent implements OnDestroy {
error: () => {
this.loginUrl.set(this.authService.getTelegramLoginUrl());
this.qrStatus.set('error');
this.startSessionPolling();
}
});
}
private startSessionPolling(): void {
this.stopPolling();
let checks = 0;
this.pollTimer = setInterval(() => {
checks++;
if (checks > 100) {
this.stopPolling();
this.qrStatus.set('expired');
return;
}
this.authService.checkSessionOnce().subscribe(session => {
if (session && session.active) {
this.stopPolling();
this.syncCartAndComplete(session.sessionId);
}
});
}, 3000);
}
private startPolling(token: string): void {
this.stopPolling();
if (!token) return;