Added auth, environment brief, docker for db_migrations,frontend,backend.

This commit is contained in:
2025-12-15 23:40:34 +01:00
parent 3ab81fad8c
commit 1a5bef277d
36 changed files with 1059 additions and 132 deletions

View File

@@ -10,11 +10,47 @@ export const apiClient = axios.create({
},
});
// Add response interceptor for error handling
// Add token from localStorage on initialization
const token = localStorage.getItem('access_token');
if (token) {
apiClient.defaults.headers.common['Authorization'] = `Bearer ${token}`;
}
// Add response interceptor for token refresh on 401
apiClient.interceptors.response.use(
(response) => response,
(error) => {
// Basic error handling - can be extended if needed
async (error) => {
const originalRequest = error.config;
// Handle 401 errors with token refresh
if (error.response?.status === 401 && !originalRequest._retry) {
originalRequest._retry = true;
try {
const refreshToken = localStorage.getItem('refresh_token');
if (!refreshToken) {
throw new Error('No refresh token');
}
const response = await axios.post(`${API_BASE_URL}/auth/refresh/`, {
refresh: refreshToken
});
const { access } = response.data;
localStorage.setItem('access_token', access);
apiClient.defaults.headers.common['Authorization'] = `Bearer ${access}`;
originalRequest.headers['Authorization'] = `Bearer ${access}`;
return apiClient(originalRequest);
} catch (refreshError) {
// Refresh failed - clear tokens and redirect to login
localStorage.removeItem('access_token');
localStorage.removeItem('refresh_token');
window.location.href = '/login';
return Promise.reject(refreshError);
}
}
return Promise.reject(error);
}
);