Build [v.1.3.6]
This commit is contained in:
@@ -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';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,6 +12,8 @@ export interface Item {
|
||||
min_quantity: number;
|
||||
image_url?: string;
|
||||
labels_data?: string;
|
||||
serial_number?: string;
|
||||
type?: string;
|
||||
}
|
||||
|
||||
export interface PendingOperation {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user