fix(api): ensure token is refreshed if not available during request
This commit is contained in:
@@ -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
@@ -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}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user