checking api

This commit is contained in:
sdarbinyan
2026-06-01 00:21:58 +04:00
parent 0d5cc8b28f
commit 7c7cdf8da2
4 changed files with 257 additions and 49 deletions

View File

@@ -4,6 +4,7 @@ import { HttpClient } from '@angular/common/http';
import { FastcheckService } from '../../fastcheck.service';
import { API_VITANOVA_NETWORK, FASTCHECK_API, FASTCHECK_STORE_API, QR_VITANOVA_API } from '../../api';
import { AuthDialogAuthorizedEvent, AuthDialogComponent, AuthDialogMode } from '../../auth-dialog/auth-dialog';
import { AuthSessionService } from '../../auth-session.service';
import { TranslatePipe } from '../../translate/translate.pipe';
import { TranslationService } from '../../translate/translation.service';
@@ -55,6 +56,7 @@ export class FastcheckPage {
private readonly defaultPartnerId = 'fast-c202-4062-bcfb-8b4c8cc59adc';
private http = inject(HttpClient);
private authSession = inject(AuthSessionService);
private store = inject(FastcheckService);
private i18n = inject(TranslationService);
@@ -277,37 +279,52 @@ export class FastcheckPage {
event.preventDefault();
const id = this.partnerId() || this.defaultPartnerId;
const sessionId = (localStorage.getItem('fc_session') ?? '').trim();
const sessionId = this.authSession.getSessionId();
if (!sessionId) {
this.openAuth('new');
return;
}
const headers: Record<string, string> = {
Authorization: JSON.stringify({ sessionID: sessionId, partnerID: id })
};
this.http
.get(`${API_VITANOVA_NETWORK}/partners/${encodeURIComponent(id)}`, { headers })
.subscribe({
next: () => {
// Authorized partner: skip Telegram auth popup and go directly.
this.doRedirectToNew(sessionId);
},
error: () => {
// Not authorized: force fresh Telegram auth QR popup.
localStorage.removeItem('fc_session');
this.authSession.validateSession(sessionId).subscribe({
next: (response) => {
if (!response) {
this.openAuth('new');
return;
}
});
const headers: Record<string, string> = {
Authorization: JSON.stringify({ sessionID: sessionId, partnerID: id })
};
this.http
.get(`${API_VITANOVA_NETWORK}/partners/${encodeURIComponent(id)}`, { headers })
.subscribe({
next: () => {
// Authorized partner: skip Telegram auth popup and go directly.
this.doRedirectToNew(sessionId);
},
error: () => {
// Not authorized: force fresh Telegram auth QR popup.
this.authSession.clearSession();
this.openAuth('new');
}
});
},
error: () => {
this.authSession.clearSession();
this.openAuth('new');
}
});
}
private doRedirectToNew(sessionId?: string): void {
const tok = sessionId || localStorage.getItem('fc_session') || '';
if (tok) {
localStorage.setItem('fc_session', tok);
const tok = sessionId || this.authSession.getSessionId() || '';
if (!tok) {
this.openAuth('new');
return;
}
window.location.href = this.newQrUrl();
}