Open raf202 opened 6 years ago
await and promises AFAIK doesn't work as getSession will complete immediately even when it takes 2-3 seconds for the token to be refreshed.
I had the same issue. Instead of calling getSession, I checked if session is not valid and we have a refresh token, then call the
https://{{appDomain}}/oauth2/token
api directly with these parameters
header: 'Content-Type': 'application/x-www-form-urlencoded' body: 'grant_type=refresh_token&client_id=${clientId}&refresh_token=${refreshToken}'
using the Fetch API. In the then block, I passed the result to onSuccessExchangeForToken
method found in this SDK.
userhandler onSuccess or onFailure is called for getSession.
I've been looking into the token refresh flow, what I would do is always call getSession with a callback to my API calls, that would make sure that my token is always valid. But I noticed in the code that getSession does not provide any callback functions.
How is the workflow to approach refresh without a callback? Setting up a timer to auto refresh seems a bit hacky to me.