Build [v.1.3.6]

This commit is contained in:
Daniel Bedeleanu
2026-04-11 17:14:22 +03:00
parent 775808506f
commit 704934165f
27 changed files with 738 additions and 685 deletions

View File

@@ -21,18 +21,15 @@ export const getBackendUrl = () => {
* [C-01] Axios instance cu JWT Bearer token în header
* și interceptor pentru 401 Unauthorized (token expired)
*/
const axiosInstance = axios.create({
baseURL: getBackendUrl()
});
const axiosInstance = axios.create({});
axiosInstance.interceptors.request.use((config) => {
if (!config.baseURL) {
config.baseURL = getBackendUrl(); // called at request time — always correct
}
const token = getToken();
console.log('[API] Request interceptor - token exists:', !!token, 'URL:', config.url);
if (token) {
config.headers.Authorization = `Bearer ${token}`;
console.log('[API] Authorization header set');
} else {
console.warn('[API] No token found in localStorage');
}
return config;
}, (error) => Promise.reject(error));
@@ -43,7 +40,7 @@ axiosInstance.interceptors.response.use(
// [L-01] Handle 401 Unauthorized — token expired
if (error.response?.status === 401) {
clearAuth();
if (typeof window !== 'undefined') {
if (typeof window !== 'undefined' && !window.location.pathname.includes('/login')) {
window.location.href = '/login';
}
}

View File

@@ -24,19 +24,12 @@ export interface AuthUser {
* Save JWT token to localStorage
*/
export const saveToken = (token: AuthToken): void => {
console.log('[Auth] saveToken called with token:', {
access_token: token.access_token?.substring(0, 20) + '...',
user_id: token.user_id,
username: token.username,
role: token.role
});
localStorage.setItem(TOKEN_KEY, token.access_token);
localStorage.setItem(USER_KEY, JSON.stringify({
id: token.user_id,
username: token.username,
role: token.role
}));
console.log('[Auth] Token saved to localStorage. TOKEN_KEY:', TOKEN_KEY);
};
/**

View File

@@ -12,6 +12,8 @@ export interface Item {
min_quantity: number;
image_url?: string;
labels_data?: string;
serial_number?: string;
type?: string;
}
export interface PendingOperation {

View File

@@ -53,7 +53,7 @@ export const fetchAndCacheItems = async () => {
const items = await inventoryApi.getItems();
// Update local cache
await db.items.clear();
await db.items.bulkAdd(items);
await db.items.bulkPut(items);
return items;
} catch (error) {
console.error('Failed to fetch items, using cache:', error);