export default defineNuxtPlugin({
setup() {
const { baseURL } = useRuntimeConfig().public;
const store = useAuthenticationStore();
const api = $fetch.create({
baseURL,
headers: {
Locale: "en",
},
onRequest({ options }) {
if (store.isAuthticated) {
options.headers = options.headers || {};
(
options.headers as Record<string, string>
).Authorization = `Bearer ${store.session.token}`;
}
},
});
return {
provide: {
api,
},
};
},
});
export default defineNuxtPlugin({
setup() {
const { baseURL } = useRuntimeConfig().public;
const store = useAuthenticationStore();
const api = $fetch.create({
baseURL,
headers: {
Locale: "en",
},
onRequest({ options }) {
if (store.isAuthticated) {
options.headers = options.headers || {};
(
options.headers as Record<string, string>
).Authorization = `Bearer ${store.session.token}`;
}
},
});
return {
provide: {
api,
},
};
},
});