base_ui/composables/useHadithaSearchComposable.ts

27 lines
801 B
TypeScript
Raw Normal View History

2025-03-15 10:11:45 +00:00
// composables/useHadithaSearchComposable.js
import { useStorage } from "@vueuse/core";
2025-03-18 12:32:36 +00:00
export const useHadithaSearchComposable = <T>(url: string, options = {}) => {
2025-03-15 10:11:45 +00:00
// Get the authentication token (e.g., from a cookie or local storage)
// const token = useCookie('auth-token') // Assuming you store the token in a cookie
let token = useStorage("id_token", "GuestAccess");
const config = useRuntimeConfig();
console.info(config);
const baseURL =
config.public.NUXT_PUBLIC_BASE_URL + config.public.NUXT_PUBLIC_API_NAME;
// Add headers to the request
const headers = {
Authorization: token.value,
...options.headers, // Merge with any existing headers
};
// Use useFetch with the headers
return useFetch<T>(url, {
...options,
2025-03-18 12:32:36 +00:00
baseURL,
2025-03-15 10:11:45 +00:00
headers,
});
};