outer-labs / react-forge-viewer

React component wrapper for Autodesk's Forge Viewer
MIT License
47 stars 23 forks source link

Missing async get token support. #6

Open sylvestrevgen opened 4 years ago

sylvestrevgen commented 4 years ago

When I replace static token data with fetch from API, in result token is undefined, but endpoint is correct. How I need to rewrite code example to use fetch token? Thanks.

borisevstratov commented 3 years ago

I managed to solve this problem by modifying the code in App.js:

  /* Once the viewer has initialized, it will ask us for a forge token so it can
  access the specified document. */
  async handleTokenRequested(onAccessToken) {
    console.log('Token requested by the viewer.');
    if (onAccessToken) {
      let token = await getPublicToken();
      if (token) {
        onAccessToken(token.access_token, token.expires_in);
      }
    }
  }

where getPublicToken() is a function that retrieves the token.