You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice if the client could be responsible for managing refreshing the token (optionally). Here is some code I've written that achieves this externally:
constclient=newSpotifyWebApi(this.config);constthat=this;consthandler={// `apply` is a trap for function callsapply: (target: any,arg: any,args: any)=>{returntarget(args);console.log('is this real life');},// `get` is a trap for object properties. All of the// methods/namespaces on the SpotifyClient are objects,// so this is the trap that's triggered, even though we// are calling functions on the client.get: (target: any,prop: any)=>{if(!that.tokenExpired()){returntarget[prop];}const ignoredFunctions =['getRefreshedAccessToken','getAccessToken','http','setAccessToken','clientId','clientSecret','then','constructor']if(ignoredFunctions.indexOf(prop)!==-1){returntarget[prop];}returnthat.refreshAccessToken().then(()=>{// console.log(`new token: ${that.authToken}`);returntarget[prop];});},};constclientProxy=newProxy(client,handler);this.client=clientProxy;
I've excluded some code here, where I initially call getRefreshableAuthorizationUrl, for brevity.
It would be ideal if the client just did a check internally to see if the token needed to be refreshed, and did it for the user. What do you think?
The text was updated successfully, but these errors were encountered:
It would be nice if the client could be responsible for managing refreshing the token (optionally). Here is some code I've written that achieves this externally:
I've excluded some code here, where I initially call
getRefreshableAuthorizationUrl
, for brevity.It would be ideal if the client just did a check internally to see if the token needed to be refreshed, and did it for the user. What do you think?
The text was updated successfully, but these errors were encountered: