2 Commits

Author SHA1 Message Date
sdarbinyan
ab1732d74b guid 2026-04-14 13:49:54 +04:00
sdarbinyan
7df15a4243 phone number 2026-04-14 13:48:56 +04:00
3 changed files with 24 additions and 7 deletions

View File

@@ -19,6 +19,25 @@ const REGION_HEADER_MAP: Record<string, string> = {
'yerevan': 'Yerevan',
};
const SESSION_STORAGE_KEY = 'web_session_id';
/** Generate a 32-char hex string (GUID without dashes) */
function generateSessionId(): string {
const bytes = new Uint8Array(16);
crypto.getRandomValues(bytes);
return Array.from(bytes, b => b.toString(16).padStart(2, '0')).join('');
}
/** Get or create a persistent anonymous session ID */
function getAnonymousSessionId(): string {
let id = localStorage.getItem(SESSION_STORAGE_KEY);
if (!id || id.length !== 32) {
id = generateSessionId();
localStorage.setItem(SESSION_STORAGE_KEY, id);
}
return id;
}
export const apiHeadersInterceptor: HttpInterceptorFn = (req, next) => {
if (!req.url.startsWith(environment.apiUrl)) {
return next(req);
@@ -42,9 +61,7 @@ export const apiHeadersInterceptor: HttpInterceptorFn = (req, next) => {
headers = headers.set('X-Language', LANG_HEADER_MAP[lang] ?? lang.toUpperCase());
}
headers = headers.set('Currency', currency || 'RUB');
if (session?.sessionId) {
headers = headers.set('WebSessionID', session.sessionId);
}
headers = headers.set('WebSessionID', session?.sessionId || getAnonymousSessionId());
return next(req.clone({ headers }));
};

View File

@@ -12,8 +12,8 @@ export const environment = {
telegram: '@novomarket',
telegramBot: 'novomarket_bot',
phones: {
armenia: '+374 98 731231',
support: '+374 98 731231'
russia: '+7 916 109 10 32',
support: '+7 916 109 10 32'
},
useMockData: false
};

View File

@@ -12,8 +12,8 @@ export const environment = {
telegram: '@novomarket',
telegramBot: 'novomarket_bot',
phones: {
armenia: '+374 98 731231',
support: '+374 98 731231'
russia: '+7 916 109 10 32',
support: '+7 916 109 10 32'
},
useMockData: false
};