Ah yes, that was a placeholder, I originally used an await before, but either way I get this error?
When I check that, it’s looking for the appbridge instance which it says is undefined, however when I log the app instance its properly returning the app object with its context etc.
Once again, I really appreciate the help so far, I realize the thread has gone on a bit of a tangent
Can you wrap the getSessionToken inside if (window.app) { ... } or moving it around to make sure there is no async call?
I suspect you have some kind of async code causing first window.app passing to getSessionToken is undefined.
Perfect thanks! Yep there ended up being two issues, there was the async stuff and then the getSessionToken from window.app had to be from just app in my case. Using this format worked out:
if(app){
const sessionTok = getSessionToken(app);
console.log("Current App: ", app);
sessionTok
.then((token) => {
console.log(‘This is my token’, token);
})
.catch((error) => {
console.log(‘Something wrong happens’, error);
});
}
Thanks for all the help!
Could you explain this error a bit more?
I recently upgraded @Shopify_77 /app-bridge-react and @Shopify_77 /app-bridge-utils to 2.02 and I’ve been receiving the following error on my queries:
Error: Network error: Unexpected token N in JSON at position 0
I’ve tested my query in the Shopify GraphiQL App and it works fine there. Here is my query:
export const GET_NEXT_PRODUCTS = gqlquery ($first: Int, $cursor: String) { products(first: $first, after: $cursor) { pageInfo { hasNextPage hasPreviousPage } edges { cursor node { id title handle description images(first: 1) { edges { node { originalSrc altText } } } tiktok: metafield ( namespace: "tiktok" key: "tiktok") { value id } } } } };
And server.js:
router.post(“/graphql”, async (ctx, next) => {
const bearer = ctx.request.header.authorization;
const secret = process.env.SHOPIFY_API_PRIVATE_KEY;
const valid = isVerified(bearer, secret);
if (valid) {
const token = bearer.split(" ")[1];
const decoded = jwt.decode(token);
const shop = new URL(decoded.dest).host;
const accessToken = store.get(‘token’);
if (shop) {
const proxy = graphQLProxy({
shop: shop,
password: accessToken,
version: ApiVersion.April21,
});
await proxy(ctx, next);
} else {
ctx.res.statusCode = 403;
}
}
});