From 1decc08f77916ee4a7f69e492ab3e172b1c69548 Mon Sep 17 00:00:00 2001 From: sdarbinyan Date: Fri, 19 Jun 2026 12:43:25 +0400 Subject: [PATCH] userId --- src/app/models/auth.model.ts | 4 ++-- src/app/pages/cart/cart.component.ts | 3 ++- src/app/services/auth.service.ts | 10 +++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/app/models/auth.model.ts b/src/app/models/auth.model.ts index 4041d57..55fac5f 100644 --- a/src/app/models/auth.model.ts +++ b/src/app/models/auth.model.ts @@ -1,10 +1,10 @@ export interface AuthSession { sessionId: string; - telegramUserId: any; + userId: any; username: string | null; displayName: string; active: boolean; - expiresAt: string; + expires: string; } export interface WebSessionStart { diff --git a/src/app/pages/cart/cart.component.ts b/src/app/pages/cart/cart.component.ts index eb8ace7..4de347e 100644 --- a/src/app/pages/cart/cart.component.ts +++ b/src/app/pages/cart/cart.component.ts @@ -437,7 +437,8 @@ export class CartComponent implements OnDestroy { } private getTelegramUserId(): string | null { - const sessionTelegramUserId = this.authService.session()?.telegramUserId; + console.log('Getting Telegram User ID', this.authService.session(), window.Telegram?.WebApp?.initDataUnsafe?.user); + const sessionTelegramUserId = this.authService.session()?.userId; if (sessionTelegramUserId) { return sessionTelegramUserId.toString(); } diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index a0736a6..cb01e74 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -153,7 +153,7 @@ export class AuthService { this.sessionSignal.set(session); this.statusSignal.set('authenticated'); this.setStoredWebSessionID(session.sessionId); - this.scheduleSessionRefresh(session.expiresAt); + this.scheduleSessionRefresh(session.expires); } private clearAuthState(status: AuthStatus): void { @@ -214,19 +214,19 @@ export class AuthService { const explicitDisplayName = this.readString(this.readFirst(response, ['displayName', 'DisplayName', 'name', 'Name'])) ?? this.readString(this.readFirst(user, ['displayName', 'DisplayName', 'name', 'Name'])) const displayName = explicitDisplayName ?? username ?? (fullName || 'Telegram User'); - const telegramUserId = this.readNumber(this.readFirst(user, ['telegramUserId', 'telegramUserID', 'TelegramUserID', 'id', 'ID'])) - ?? this.readNumber(this.readFirst(response, ['telegramUserId', 'telegramUserID', 'TelegramUserID', 'userID', 'UserID'])) + const telegramUserId = this.readNumber(this.readFirst(user, ['userId','telegramUserId', 'telegramUserID', 'TelegramUserID', 'id', 'ID'])) + ?? this.readNumber(this.readFirst(response, ['telegramUserId', 'telegramUserID', 'TelegramUserID', 'userID', 'UserID', 'UserId'])) ?? 0; const expiresAt = this.readString(this.readFirst(response, ['expiresAt', 'ExpiresAt', 'expires', 'Expires'])) ?? new Date(Date.now() + WEB_SESSION_COOKIE_MAX_AGE_SECONDS * 1000).toISOString(); return { sessionId, - telegramUserId, + userId: telegramUserId, username, displayName, active, - expiresAt, + expires: expiresAt, }; }