This commit is contained in:
sdarbinyan
2026-06-19 12:43:25 +04:00
parent c0cfbcbcbb
commit 1decc08f77
3 changed files with 9 additions and 8 deletions

View File

@@ -1,10 +1,10 @@
export interface AuthSession { export interface AuthSession {
sessionId: string; sessionId: string;
telegramUserId: any; userId: any;
username: string | null; username: string | null;
displayName: string; displayName: string;
active: boolean; active: boolean;
expiresAt: string; expires: string;
} }
export interface WebSessionStart { export interface WebSessionStart {

View File

@@ -437,7 +437,8 @@ export class CartComponent implements OnDestroy {
} }
private getTelegramUserId(): string | null { 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) { if (sessionTelegramUserId) {
return sessionTelegramUserId.toString(); return sessionTelegramUserId.toString();
} }

View File

@@ -153,7 +153,7 @@ export class AuthService {
this.sessionSignal.set(session); this.sessionSignal.set(session);
this.statusSignal.set('authenticated'); this.statusSignal.set('authenticated');
this.setStoredWebSessionID(session.sessionId); this.setStoredWebSessionID(session.sessionId);
this.scheduleSessionRefresh(session.expiresAt); this.scheduleSessionRefresh(session.expires);
} }
private clearAuthState(status: AuthStatus): void { private clearAuthState(status: AuthStatus): void {
@@ -214,19 +214,19 @@ export class AuthService {
const explicitDisplayName = this.readString(this.readFirst(response, ['displayName', 'DisplayName', 'name', 'Name'])) const explicitDisplayName = this.readString(this.readFirst(response, ['displayName', 'DisplayName', 'name', 'Name']))
?? this.readString(this.readFirst(user, ['displayName', 'DisplayName', 'name', 'Name'])) ?? this.readString(this.readFirst(user, ['displayName', 'DisplayName', 'name', 'Name']))
const displayName = explicitDisplayName ?? username ?? (fullName || 'Telegram User'); const displayName = explicitDisplayName ?? username ?? (fullName || 'Telegram User');
const telegramUserId = this.readNumber(this.readFirst(user, ['telegramUserId', 'telegramUserID', 'TelegramUserID', 'id', 'ID'])) const telegramUserId = this.readNumber(this.readFirst(user, ['userId','telegramUserId', 'telegramUserID', 'TelegramUserID', 'id', 'ID']))
?? this.readNumber(this.readFirst(response, ['telegramUserId', 'telegramUserID', 'TelegramUserID', 'userID', 'UserID'])) ?? this.readNumber(this.readFirst(response, ['telegramUserId', 'telegramUserID', 'TelegramUserID', 'userID', 'UserID', 'UserId']))
?? 0; ?? 0;
const expiresAt = this.readString(this.readFirst(response, ['expiresAt', 'ExpiresAt', 'expires', 'Expires'])) const expiresAt = this.readString(this.readFirst(response, ['expiresAt', 'ExpiresAt', 'expires', 'Expires']))
?? new Date(Date.now() + WEB_SESSION_COOKIE_MAX_AGE_SECONDS * 1000).toISOString(); ?? new Date(Date.now() + WEB_SESSION_COOKIE_MAX_AGE_SECONDS * 1000).toISOString();
return { return {
sessionId, sessionId,
telegramUserId, userId: telegramUserId,
username, username,
displayName, displayName,
active, active,
expiresAt, expires: expiresAt,
}; };
} }