Gadget API in Purchase Options Extension Permissions Issue

I've created a purchase options extension for my app following this guide: https://shopify.dev/docs/apps/build/purchase-options/purchase-options-extensions/start-building And I setup to use Gadget API for it by using this guide: https://docs.gadget.dev/api/example-app/development/external-api-calls/installing#creating-the-client-for-react-apps In development it works fine, I can access my resources. However, when I deployed extension in Prod when trying to get my resources I get error: Error fetching preorderCampaign: CombinedError: [GraphQL] GGT_PERMISSION_DENIED: The unauthenticated role cannot read preorderCampaign records. Why it works fine in development and not in production? My app is: https://kedra-preorder.gadget.app/
No description
8 Replies
emabaran
emabaranOP2mo ago
This is the api.js:
import { Client } from "@gadget-client/kedra-preorder";

export const api = new Client({
authenticationMode: { browserSession: true },
});
import { Client } from "@gadget-client/kedra-preorder";

export const api = new Client({
authenticationMode: { browserSession: true },
});
I was wondering maybe it has something to do with managed installs? Because in development I do not use managed installs but in prod I do. I also tried enabling unauthenticated permissions for this model just to test some things out, but it seems to return null even though the entry exists.
Smelvin
Smelvin2mo ago
Hello Emabaran, Im looking through the files and I cant see any reference to preOrderCampaign. Where in your app are you making calls to the api?
emabaran
emabaranOP2mo ago
what do you mean? It’s a model in my app
Smelvin
Smelvin2mo ago
One thing I can see is that within your code there is no API calls to fetch preorderCampaign data. I would recommend looking at this doc for what changes need to be made in your code for properly setting up the session token :https://docs.gadget.dev/guides/plugins/shopify/advanced-topics/extensions#sending-the-session-token
emabaran
emabaranOP2mo ago
but why in development it works fine? and it production it does not?
Smelvin
Smelvin2mo ago
That is what I was trying to understand as well, Where is the fetch for preorderCampaign being called from purchaseOptionsActionExtension because I was not able to find any call to it because from the error code you posted it says you're trying to fetch, but I dont see anything in the code for said fetch
emabaran
emabaranOP2mo ago
I checked network logs and it seems it keeps fetching with development api and not production one. I do not understand how it does this. I rechecked my toml files and they for sure do not have "--development" application_url. Can be it somehow related with installing the client and setting up registry? https://docs.gadget.dev/api/example-app/development/external-api-calls/installing#node-module Okay I found out! I just had to pass the environment to the client.
export const api = new Client({
environment: "Production",
});
export const api = new Client({
environment: "Production",
});
as such
Smelvin
Smelvin2mo ago
Happy to hear!

Did you find this page helpful?