fix(api): ensure token is refreshed if not available during request

This commit is contained in:
hamed
2026-06-21 13:47:07 +03:30
parent 609479919a
commit e0d729dcf1
2 changed files with 6 additions and 8 deletions
@@ -38,12 +38,7 @@ function Turns({ user, setIsTurnsDetails, loading }) {
const items = response?.data?.data;
if (Array.isArray(items)) {
// API برمی‌گرداند doctor_name/doctor_uuid (تخت)؛ کامپوننت‌ها doctor.name (تودرتو) می‌خواهند.
const normalized = items.map((a) => ({
...a,
doctor: { uuid: a.doctor_uuid, name: a.doctor_name, specialties: [] },
}));
setAppointments(normalized);
setAppointments(items);
} else {
setAppointments([]);
}
+5 -2
View File
@@ -54,9 +54,12 @@ function handleSessionExpired() {
}
api.interceptors.request.use(
(config) => {
async (config) => {
if (config.requireAuth) {
const token = getAccessToken();
let token = getAccessToken();
if (!token) {
token = await refreshAccessToken();
}
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}