qr login with telegram
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Injectable, signal, computed } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable, of, catchError, map, tap } from 'rxjs';
|
||||
import { AuthSession, AuthStatus } from '../models/auth.model';
|
||||
import { AuthSession, AuthStatus, QrPollResponse } from '../models/auth.model';
|
||||
import { environment } from '../../environments/environment';
|
||||
|
||||
@Injectable({
|
||||
@@ -82,6 +82,34 @@ export class AuthService {
|
||||
return this.getTelegramLoginUrl();
|
||||
}
|
||||
|
||||
/** Create a one-time QR login token via backend */
|
||||
createQrToken(): Observable<{ token: string; url: string }> {
|
||||
return this.http.post<{ token: string; url: string }>(
|
||||
`${this.apiUrl}/auth/qr/create`,
|
||||
{},
|
||||
{ withCredentials: true }
|
||||
);
|
||||
}
|
||||
|
||||
/** Poll the QR token status (pending → confirmed / expired) */
|
||||
pollQrToken(token: string): Observable<QrPollResponse> {
|
||||
return this.http.get<QrPollResponse>(
|
||||
`${this.apiUrl}/auth/qr/poll`,
|
||||
{
|
||||
params: { token },
|
||||
withCredentials: true,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/** Sync local cart to the backend session after login */
|
||||
syncCart(sessionId: string, items: Array<{ itemID: number; quantity: number; colour?: string; size?: string; price?: number }>): Observable<unknown> {
|
||||
if (!items.length) return of(null);
|
||||
return this.http.post(`${this.apiUrl}/websession/${sessionId}`, items, {
|
||||
withCredentials: true,
|
||||
}).pipe(catchError(() => of(null)));
|
||||
}
|
||||
|
||||
/** Show login dialog (called when user tries to pay without being logged in) */
|
||||
requestLogin(): void {
|
||||
this.showLoginSignal.set(true);
|
||||
|
||||
Reference in New Issue
Block a user