260322:1648 Correct Coresspondence / Doing RFA / Correct CI
CI Pipeline / build (push) Failing after 12m41s
Build and Deploy / deploy (push) Failing after 2m44s

This commit is contained in:
admin
2026-03-22 16:48:12 +07:00
parent e5deedb42e
commit 11984bfa29
683 changed files with 105251 additions and 29068 deletions
+9 -9
View File
@@ -1,15 +1,15 @@
// File: lib/api/client.ts
import axios, { AxiosInstance, InternalAxiosRequestConfig, AxiosError } from "axios";
import { v4 as uuidv4 } from "uuid";
import axios, { AxiosInstance, InternalAxiosRequestConfig, AxiosError } from 'axios';
import { v4 as uuidv4 } from 'uuid';
// อ่านค่า Base URL จาก Environment Variable
const baseURL = process.env.NEXT_PUBLIC_API_URL || "http://localhost:3001/api";
const baseURL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3001/api';
// สร้าง Axios Instance หลัก
const apiClient: AxiosInstance = axios.create({
baseURL,
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
timeout: 15000, // Timeout 15 วินาที
});
@@ -23,13 +23,13 @@ apiClient.interceptors.request.use(
// 1. Idempotency Key Injection
// ป้องกันการทำรายการซ้ำสำหรับ Method ที่เปลี่ยนแปลงข้อมูล
const method = config.method?.toLowerCase();
if (method && ["post", "put", "delete", "patch"].includes(method)) {
config.headers["Idempotency-Key"] = uuidv4();
if (method && ['post', 'put', 'delete', 'patch'].includes(method)) {
config.headers['Idempotency-Key'] = uuidv4();
}
// 2. Authentication Token Injection
// ดึง Token จาก Zustand persist store (localStorage)
if (typeof window !== "undefined") {
if (typeof window !== 'undefined') {
try {
const authStorage = localStorage.getItem('auth-storage');
if (authStorage) {
@@ -37,10 +37,10 @@ apiClient.interceptors.request.use(
const token = parsed?.state?.token;
if (token) {
config.headers["Authorization"] = `Bearer ${token}`;
config.headers['Authorization'] = `Bearer ${token}`;
}
}
} catch (error) {
} catch (_error) {
// Auth token retrieval failed - request will proceed without token
}
}