Update project 4 frontend start

This commit is contained in:
2026-03-06 11:08:45 +00:00
parent 50221c57e1
commit 0e1ee7066f
21 changed files with 6667 additions and 1 deletions

View File

@@ -0,0 +1,18 @@
import axios from "axios";
import { useAuthStore } from "@/store/authStore";
const apiClient = axios.create({
baseURL: process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:8081/api",
headers: { "Content-Type": "application/json" },
});
apiClient.interceptors.request.use((config) => {
// getState() — безопасен вне React-дерева (server actions, route handlers тоже работают)
const token = useAuthStore.getState().token;
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
});
export default apiClient;