Cesium Ion Token invalid with missing auth token

I am setting my Ion token but am getting a 401 error:

RequestErrorEvent {statusCode: 401, response: '{"code":"InvalidCredentials","message":"No authorization token was found"}', responseHeaders: {…}}

It’s possible that the token is not being set before the Viewer is being rendered and assets loaded. The error is from this endpoint: GET https://api.cesium.com/v1/assets/2/endpoint 401

This error only thrown if I set the token and only for the Ion token it seems.

Ion.defaultAccessToken = process.env.REACT_APP_CESIUM_ION_TOKEN!;
GoogleMaps.defaultApiKey = process.env.REACT_APP_GOOGLE_MAPS_API_KEY!;

Does the setting of tokens need to happen asynchronously before the Viewer is mounted?

Hi there,

Depending on the configuration, the Viewer make some requests to ion upon creation. So yes, in many cases, you will need to set Ion.defaultAccessToken before the Viewer is instantiated.

But you can pass options which will not reach out to ion at all, such as setting globe: false. Would you mind providing the code you’re using to instantiate the viewer?