QR login
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user