Closed MikeWillis closed 3 months ago
Hey Mike, Thanks for the PR. I will review this as soon as I get a chance to do so.
Apologies on the radio silence. This repo is now being maintained again and a new major version has been released that impacts this PR. I think this PR is a good idea - my only concern is how to pass the refreshed API key back out to be stored? If you want to revise this for the updated version I will be happy to merge.
I wanted my app to automatically refresh the token if necessary, instead of triggering a fatal error. So I added a config option
autoRefreshSettings
where you can pass an array of settings for refreshing the token. If set, a401
/invalid_token
response will trigger a token refresh followed by a recursive call, so the refresh is seamless.If the refresh is successful, the new access token and refresh tokens are stored for use on future calls. I also pass in an
onSuccess
handler, which you can use to save the new tokens somewhere in your DB.I suppose you could just start every script with a call to the refresh token.. But I wanted to only run the refresh when necessary.
Example usage: