15 lines
360 B
JavaScript
15 lines
360 B
JavaScript
import { ofetch } from 'ofetch'
|
|
|
|
export const $api = ofetch.create({
|
|
baseURL: import.meta.env.VITE_API_BASE_URL || '/api',
|
|
async onRequest({ options }) {
|
|
const accessToken = useCookie('accessToken').value
|
|
if (accessToken) {
|
|
options.headers = {
|
|
...options.headers,
|
|
Authorization: `Bearer ${accessToken}`,
|
|
}
|
|
}
|
|
},
|
|
})
|