Re: app-bridge-utils.getSessionToken() promise not resolving

app-bridge-utils.getSessionToken() promise not resolving

CaveDiver
Shopify Partner
17 0 6

Hi,

The following function is fashioned after samples I have found but I'm getting neither a token nor an error.

async function getToken() {
var AppBridge = window['app-bridge'];
var actions = AppBridge.actions;
var createApp = AppBridge.default;
var app = createApp({
  apiKey: '[my-api-key]',
  shopOrigin: '[my-shop-origin]',
  forceRedirect: false
});
var utils = window['app-bridge-utils'];
try {
  var sessionToken = await utils.getSessionToken(app);
  alert("This line does not execute");
  return sessionToken; // promise, not a token
} catch(err) {
  alert("getSessionToken() returned an error");
  }
};

In debug, execution skips the rest of the try block after "getSessionToken(app)" entirely.
The calling code indicates that a promise was returned - not a token.

What am I missing here?
Thanks.

Replies 2 (2)

awwdam
Shopify Staff
249 42 37

Hey @CaveDiver,

Are you still experiencing this issue? If so, we would love to get a bit more info and take a closer look. Would you be able to confirm what documentation you are using (where examples were taken from), any specific builds and dependency versioning used, and if possible an x-request-id header returned where this functionality is present? - Thanks!

awwdam | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

CaveDiver
Shopify Partner
17 0 6

I was trying to do this in a shopper-facing page in the online store.  As a test, I tried the same code in a merchant-facing page in the store admin and it worked fine.

So the problem was not with my code but rather with figuring out what can and cannot be done within the so-called Shopify ecosystem.
A simple error message from app-bridge-utils would have saved me a lot of time.