import { Api } from '~/api/Api' const api = new Api({ baseUrl: String('https://wp.koptilnya.xyz/wp-json'), }) const nativeRequest = api.request const consumerKey = 'ck_8b5477a1573ce6038ef1367f25d95cede1de4559' const consumerSecret = 'cs_d0ccaa93e8efe4f76eef0b70c9828a58fc53459f' const authString = `${consumerKey}:${consumerSecret}` const encodedAuth = btoa(authString) // Кодируем в Base64 (браузерный метод) api.request = async function (...args) { const [url, options = {}] = args const headers = { ...options.headers, 'Authorization': `Basic ${encodedAuth}`, 'Content-Type': 'application/json', // Явно указываем JSON } // Убираем credentials: "omit" (мешает передаче заголовков) const fetchOptions = { ...options, headers, credentials: 'same-origin', // или "include" для кросс-доменных запросов } console.log('Отправляемые заголовки:', headers) console.log('fetchOptions', fetchOptions) const response = await nativeRequest.call(api, url, fetchOptions) return await response.json() } export default api