Hi
I was using a code to fetch data from an endpoint that will always respond with ok 200 status, it works just fine until I use the Bearer authorization.
Backend data.jsw:
import {fetch} from 'wix-fetch';
import wixSecretsBackend from 'wix-secrets-backend';
let baseUrl = // My API URL;
export async function getTutorials() {
let token = await wixSecretsBackend.getSecret('MyAPIKey');
const headers = {
"Authorization": `Bearer ${token}`,
"Content-Type": "application/json"
};
let url = baseUrl + "tutorials"
return fetch(url, { method: "get", headers: headers }).then( (httpResponse) => {
if (httpResponse.ok) {
return httpResponse.json();
} else {
return Promise.reject(httpResponse.body.error);
}
}).catch(err => {
console.error(err);
return Promise.reject("Fetch did not succeed");
})
}
Any idea?
Help is appreciated.
Thanks.