mongodb-js / charts-embed-sdk

The easiest way to embed MongoDB Charts visualisations into your web app
https://docs.mongodb.com/charts/master/embedding-charts-sdk/
Apache License 2.0
43 stars 31 forks source link

First request returns 404 with JWT #33

Closed ppascualv closed 3 years ago

ppascualv commented 3 years ago

Describe the bug When charts are rendered using a JWT seem that the first fetch is returning 404 and the auth header is not present, however, it automatically does a retry with the correct header.

To Reproduce I'm using React

  useEffect(() => {
    const newSdk = new ChartsEmbedSDK({
      baseUrl: "https://charts.mongodb.com/charts-swipcar-iukiy",
      showAttribution: false,
      theme: "light",
      getUserToken
    })
    setSdk(newSdk)
  }, [])

async function getUserToken() {
  const x = await getChartsAuthToken()
    .then(response => {
      return response.data.authToken
    })
    .catch(() => console.error("Chart auth failed"))

  return x
}

Expected behavior They should not generate 404 requests

Screenshots image failing request: image response: {"errorCode":3,"simple":"Error loading data for this chart (error code: 3).","verbose":"Error loading data for this chart (error code: 3). Embedding not enabled on this chart. See https://dochub.mongodb.org/core/charts-embedding-error-codes for details."} good request: image

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

tomhollander commented 3 years ago

Thanks @ppascualv - this should be fixed in the 2.1.0-beta.1 version - could you please check that and let me know if it's still an issue? We'll include this fix in the next release version.

ppascualv commented 3 years ago

Seems fixed @tomhollander. Thanks!