import axios from 'axios'
import { usePage } from '@inertiajs/vue3'
import {SharedProps} from "@/Types/types";

export const api = axios.create({
    baseURL: import.meta.env.VITE_API_URL,
    withCredentials: true,
    headers: { Accept: 'application/json' },
})

api.interceptors.request.use((config) => {
    const token = usePage<SharedProps>().props.auth?.apiToken
    if (token) {
        config.headers.Authorization = `Bearer ${token}`
    }
    return config
})
