oidc-client-ts
                                
                                
                                
                                    oidc-client-ts copied to clipboard
                            
                            
                            
                        Network error after waking up from sleep
We see in Chrome after PC woke up from sleep:
POST 
and the library isn't recovering from that error (automaticSilentRenew is true) and token renewal is working fine otherwise. I guess the timeout solution implemented in Waking up from sleep #251 doesn't help because the connection can't be established in the first place.
Thanks, Daniel
Running into the same issue on version 2.4.0 and node v16.20.1.
My current workaround is to attempt a token renewal on token expiry event by explicitly waiting for both network connectivity and internet access. Looks something like this:
this.userManager.events.addAccessTokenExpired(() => {
  new Promise<void>(resolve => {
    const interval = setInterval(() => {
      // navigator.onLine only checks for network connectivity but not internet access. Need to manually check
      if (navigator.onLine)
        fetch(new Request(window.location.origin)) // whatever endpoint allowed by cors policy you want to hit
          .then(v => {
            if (v.ok) {
              clearInterval(interval)
              resolve()
            }
          })
    }, 1000)
  }).then(() => {
    console.debug('Token expired. Attempting silent renew.')
    this.userManager.signinSilent().catch((e) => {
      console.error('Silent renew error from access token expiry event: ', e)
      // if you end up here you might want to start a signout process
    })
  })
})
                                    
                                    
                                    
                                
This looks promising. The offline status is correctly telling that the browser is online. However, the Mozilla docs states "you cannot assume that a true value necessarily means that the browser can access the internet." https://developer.mozilla.org/en-US/docs/Web/API/Navigator/onLine
So what about "pinging" the well-known endpoint additionally when navigator.onLine is true
    fetch('<op-well-known-endpoint>', {
        method: 'GET',
        mode: 'no-cors',
    }).then((result) => {
        console.log("online")
    }).catch(e => {
        console.log("offline")
    })
It's an additional call but makes sure that there is really an internet connection. Would that work?
Hi, is there any update here? we want to go live next month with our solution.
@CanD42 ~In https://github.com/authts/oidc-client-ts/issues/1435 I suggested to emit an USER_UNLOADED event when the refresh token requests fails. Would this behavior be ok for your use case too?~
Sorry, I noticed there is already a special silentRenewError event, which can be used in my use case.