<script setup>
import axios from "axios";
import {useRouter} from "vue-router";
import store from '@/store'

const router = useRouter()
axios.get("/sanctum/csrf-cookie").catch(() => {});
axios.interceptors.request.use(
  (config) => {
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);
axios.interceptors.response.use(
  (response) => {
    return response;
  },
  (error) => {
    if (error.response.status === 401) {
      store.dispatch("auth/logout");
      router.push({ name: "login" });
    }

    return Promise.reject(error);
  }
);
</script>

<template>
  <router-view />
</template>

<style scoped></style>
