iTwin / viewer-components-react

Components built on iTwin.js for usability in an iTwin.js based Viewer.
MIT License
24 stars 33 forks source link

Error in Property Grid when the browser tab is inactive for more than 10 minutes #736

Closed muthubentley closed 7 months ago

muthubentley commented 8 months ago

Issue: Error in Property Grid when the browser tab is inactive for more than 10 minutes. Refer the below screenshot for error description: 画像 (1)

Steps to reproduce: Partner has developed a site with iTwin viewer. Issue is occurring in their website. 1) Open multiple tabs of iTwin viewer 2) Select an element in viewport and confirm that Property Grid pops up 3) Switch the tab and leave it as it is for around 10 to 15 minutes 4) Come back to the tab . Error occurs at this point. 5) Even if they press the retry button same error occurs again. If they refresh the browser then it comes back to normal

Not sure if it is related they could see the below API throwing 401 Request URL: https://api.bentley.com/imodel/rpc/v4/mode/1/context/850ef36a-18a0-4595-8fa7-9285d7276980/imodel/2064aefd-8bc6-4e0a-b670-374f87e023e0/changeset/12b84bed1ef6c6534ef0a65d11142fe00776a985/PresentationRpcInterface-4.0.0-getPagedContent Response: {"statusCode": 401, "message": "Invalid JWT."}

Please investigate why this error is occurring and let us know if there are any workarounds.

aruniverse commented 8 months ago

As per the error message, the users access token expired and they need a new one

muthubentley commented 8 months ago

@aruniverse I understand. Is the below explanation correct: Normally when the tab is active this error doesnt occur. Which means there is a mechanism in place to refresh the expired token. But that mechanism will not work if the tab is inactive. 2 questions on this:

  1. Is there anyway to make this refresh token work when the user comes back to tab? I thought retry button was given for that purpose. But clicking that doesnt refresh the token so wanted to check if there is any other way.
  2. Is it possible to extend the lifetime of user access token?
grigasp commented 8 months ago

Is there anyway to make this refresh token work when the user comes back to tab? I thought retry button was given for that purpose. But clicking that doesnt refresh the token so wanted to check if there is any other way.

The "retry" button attempts to mount the component again, which in turn makes another request for properties. If the token is invalid, the second request fails too. Property grid by itself does absolutely nothing related to access tokens - it's acquired somewhere behind the scenes in itwinjs-core.

muthubentley commented 8 months ago

@grigasp thanks for the explanation. retry button makes sense. @aruniverse can you confirm this: Is the below explanation correct: Normally when the tab is active this error doesnt occur. Which means there is a mechanism in place to refresh the expired token. But that mechanism will not work if the tab is inactive. Questions:

  1. Is there anyway to make this refresh token work when the user comes back to tab?
  2. Is it possible to extend the lifetime of user access token?
aruniverse commented 7 months ago

It is the responsibility of the Auth Client to refresh the token. If the tab is suspended then i guess its unable to do so, but it should be possible for you to add additional behavior to refresh the token (if needed) when your context switches back to the tab.

There is no way to extend the lifetime of an access token, you need to use the refresh token to get an updated access token

muthubentley commented 7 months ago

@aruniverse Thanks for the explanation. Seems the problem is in Fukui's client side. Sorry for the trouble, closing the issue.