Having some trouble with getting a list of themes in a store. I've installed a fresh version of the shopify app as shown on the shopify dev docs.
When I console log the response I get this:
Am I missing something obvious or important?
It's not clear, from the code you have shared, what kind of fetch
you're using.
You should use the fetch provided by the template:
import {useAuthenticatedFetch} from "./hooks/index.js";
const fetch = useAuthenticatedFetch();
which I'm reporting here to have a complete answer:
export function useAuthenticatedFetch() {
const app = useAppBridge();
const fetchFunction = authenticatedFetch(app);
return async (uri, options) => {
const response = await fetchFunction(uri, options);
checkHeadersForReauthorization(response.headers, app);
return response;
};
}
function checkHeadersForReauthorization(headers, app) {
if (headers.get("X-Shopify-API-Request-Failure-Reauthorize") === "1") {
const authUrlHeader =
headers.get("X-Shopify-API-Request-Failure-Reauthorize-Url") ||
`/api/auth`;
const redirect = Redirect.create(app);
redirect.dispatch(
Redirect.Action.REMOTE,
authUrlHeader.startsWith("/")
? `https://${window.location.host}${authUrlHeader}`
: authUrlHeader
);
}
}