251225:1703 On going update to 1.7.0: Refoctory drawing Module not finish
Some checks failed
Spec Validation / validate-markdown (push) Has been cancelled
Spec Validation / validate-diagrams (push) Has been cancelled
Spec Validation / check-todos (push) Has been cancelled

This commit is contained in:
admin
2025-12-25 17:03:33 +07:00
parent 7db6a003db
commit cd73cc1549
60 changed files with 8201 additions and 832 deletions

View File

@@ -1,7 +1,6 @@
// File: lib/api/client.ts
import axios, { AxiosInstance, InternalAxiosRequestConfig, AxiosError } from "axios";
import { v4 as uuidv4 } from "uuid";
import { getSession } from "next-auth/react";
// อ่านค่า Base URL จาก Environment Variable
const baseURL = process.env.NEXT_PUBLIC_API_URL || "http://localhost:3001/api";
@@ -29,18 +28,20 @@ apiClient.interceptors.request.use(
}
// 2. Authentication Token Injection
// ดึง Session จาก NextAuth (ทำงานเฉพาะฝั่ง Client)
// ดึง Token จาก Zustand persist store (localStorage)
if (typeof window !== "undefined") {
try {
const session = await getSession();
// @ts-ignore: Session type extended in types/next-auth.d.ts
const token = session?.accessToken;
const authStorage = localStorage.getItem('auth-storage');
if (authStorage) {
const parsed = JSON.parse(authStorage);
const token = parsed?.state?.token;
if (token) {
config.headers["Authorization"] = `Bearer ${token}`;
if (token) {
config.headers["Authorization"] = `Bearer ${token}`;
}
}
} catch (error) {
console.warn("Failed to retrieve session token:", error);
console.warn("Failed to retrieve auth token:", error);
}
}
@@ -73,4 +74,4 @@ apiClient.interceptors.response.use(
}
);
export default apiClient;
export default apiClient;