diff --git a/front/MyINPulse-front/src/components/GetAppointments.vue b/front/MyINPulse-front/src/components/GetAppointments.vue new file mode 100644 index 0000000..bc84e0d --- /dev/null +++ b/front/MyINPulse-front/src/components/GetAppointments.vue @@ -0,0 +1,90 @@ + + + + + diff --git a/front/MyINPulse-front/src/services/api.ts b/front/MyINPulse-front/src/services/api.ts index fe3295a..b5cc3ac 100644 --- a/front/MyINPulse-front/src/services/api.ts +++ b/front/MyINPulse-front/src/services/api.ts @@ -10,6 +10,19 @@ 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 +33,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");