Compare commits
2 Commits
4a33b8defa
...
eee26d06b7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eee26d06b7 | ||
|
|
e0f22b6c5a |
23
taskncoffee-app/src/apiv1/client.js
Normal file
23
taskncoffee-app/src/apiv1/client.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import axios from 'axios';
|
||||
import { API_BASE_URL, API_V1_PREFIX } from './ApiSources';
|
||||
|
||||
|
||||
const client = axios.create({
|
||||
baseURL: `${API_BASE_URL}${API_V1_PREFIX}`,
|
||||
timeout: 10000,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
withCredentials: true,
|
||||
});
|
||||
|
||||
client.interceptors.request.use(
|
||||
(config) => {
|
||||
const token = localStorage.getItem('access_token');
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
return config;
|
||||
},
|
||||
);
|
||||
export default client;
|
||||
42
taskncoffee-app/src/apiv1/fingerprint.js
Normal file
42
taskncoffee-app/src/apiv1/fingerprint.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import FingerprintJS from '@fingerprintjs/fingerprintjs';
|
||||
|
||||
let fpPromise = null;
|
||||
|
||||
/**
|
||||
* @returns {Promise} Promise с экземпляром FingerprintJS
|
||||
*/
|
||||
const initFingerprint = () => {
|
||||
if (!fpPromise) {
|
||||
fpPromise = FingerprintJS.load();
|
||||
}
|
||||
return fpPromise;
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {Promise<string>} Fingerprint ID
|
||||
*/
|
||||
export const getFingerprint = async () => {
|
||||
try {
|
||||
const savedFingerprint = localStorage.getItem('fingerprint');
|
||||
if (savedFingerprint) {
|
||||
return savedFingerprint;
|
||||
}
|
||||
|
||||
const fp = await initFingerprint();
|
||||
const result = await fp.get();
|
||||
const fingerprint = result.visitorId;
|
||||
|
||||
localStorage.setItem('fingerprint', fingerprint);
|
||||
return fingerprint;
|
||||
} catch (error) {
|
||||
console.error('Error getting fingerprint:', error);
|
||||
const fallbackFingerprint = `fallback_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
||||
localStorage.setItem('fingerprint', fallbackFingerprint);
|
||||
return fallbackFingerprint;
|
||||
}
|
||||
};
|
||||
|
||||
export const clearFingerprint = () => {
|
||||
localStorage.removeItem('fingerprint');
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user