Compare commits
2 Commits
abb74390e8
...
ab1732d74b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ab1732d74b | ||
|
|
7df15a4243 |
@@ -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 }));
|
||||
};
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user