checking api
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user