Open nickezekias opened 2 months ago
Here is the problematic code:
axios.interceptors.response.use(
(response) => {
return response;
},
async function (error) {
if (
error.response &&
[401, 419].includes(error.response.status)
) {
const authStore = useAuthStore() // PROBLEM CODE TO FIX
await authStore.logout()
}
return Promise.reject(error);
}
);
authStore is used before pinia store is injected into vue app
In lib/axios.ts I'm currently using axios.interceptors.response to detect a 401 or 419 response to trigger a logout system wide, but I have a problem with the way authStore is injected. It gets used before pinia is injected into vue app.
Find a way either using a plugin or creating a service class and injecting axios as library in store files to make sure pinia is injected before axios is used.