Closed ankesh7 closed 3 years ago
in your ComponentNeedingToken.js, try to get app by
const app = useAppBridge();
and get token from here :
const token = await getSessionToken(app);
Thanks @hrstrand that surely worked. I don't have experience creating GitHub issues but I can tell your reply with the solution surely belongs to among the fastest (< 30s). Cheers dude 😄
Issue summary
I am trying to get a session token using import { getSessionToken } from @shopify/app-bridge-utils so that I can get token and add it to the Authorization header in my fetch calls. I am getting this errorAppBridgeError: APP::ERROR::INVALID_CONFIG: shopOrigin must be provided . This happened while I tried to upgrade to the latest version of the library which handles. I went through the upgrade guide and just wasn't sure about the last part that says to replace all fetch calls in frontend to authenticatedFetch. In my case, I am not using GraphQL hence all of my calls are wired up using native fetch calls that's speak to koa routes. Based on this source I am trying to get tokens and failing to get one. All of my fetch calls are redirecting to /auth I guess because of the missing Authorization token and verify request middleware fails.
My app works well on every install as expected is functions as an embedded app on initial load but all of the fetch calls on user interaction don't work because of the above issue.
_app.js
ComponentNeedingToken.js
Console print for app config to ensure shopOrigin is set by the server. This is printed both serverside and client-side as I am using Next.js
server.js