lister tout les upcoming appointmens
Some checks failed
Format / formatting (push) Successful in 6s
Build / build (push) Successful in 43s
CI / build (push) Failing after 11s
Format / formatting (pull_request) Successful in 6s

This commit is contained in:
root
2025-05-01 15:26:05 +02:00
parent 92696c3e16
commit f46c3756f0
3 changed files with 92 additions and 5 deletions

View File

@ -10,6 +10,20 @@ const axiosInstance = axios.create({
},
});
axiosInstance.interceptors.request.use(
(config) => {
const token = store.user?.token; // Récupérez le token depuis le store
if (token) {
config.headers["Authorization"] = `Bearer ${token}`; // Ajoutez le token dans l'en-tête
}
return config;
},
(error) => {
return Promise.reject(error);
}
);
axiosInstance.interceptors.response.use(
(response) => response, // Directly return successful responses.
async (error) => {
@ -20,15 +34,13 @@ axiosInstance.interceptors.response.use(
!originalRequest._retry &&
store.authenticated
) {
originalRequest._retry = true; // Mark the request as retried to avoid infinite loops.
originalRequest._retry = true;
try {
await store.refreshUserToken();
// Update the authorization header with the new access token.
axiosInstance.defaults.headers.common["Authorization"] =
`Bearer ${store.user.token}`;
return axiosInstance(originalRequest); // Retry the original request with the new access token.
return axiosInstance(originalRequest);
} catch (refreshError) {
// Handle refresh token errors by clearing stored tokens and redirecting to the login page.
console.error("Token refresh failed:", refreshError);
localStorage.removeItem("accessToken");
localStorage.removeItem("refreshToken");