You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
629 B

  1. import axios from 'axios'
  2. import router from '@/router'
  3. import admin from '@/store/admin/index.js'
  4. const instance = axios.create({
  5. baseURL: "http://localhost:8080/api/v1/",
  6. headers: {
  7. "Content-Type": "application/json",
  8. },
  9. });
  10. instance.interceptors.response.use(
  11. function (response) {
  12. return response;
  13. },
  14. function (error) {
  15. if (error.response.status === 401) {
  16. admin.dispatch('setUser', null)
  17. router.push({ name: 'AdminLogin', params: { unauthorized: true } })
  18. return
  19. }
  20. return Promise.reject(error);
  21. }
  22. );
  23. export default instance