Dealing with access tokens and refresh tokens for multiple APIs can be tricky. The challenge arises when an access token expires and needs to be updated without disrupting the functionality of the application.
The current solution involves manually updating the access token in every function that requires it, which is not ideal as it may lead to errors if the refresh token also expires.
getAllBuckets(account: GetAllBucket){
const {project, accessToken} = account
const qs = new URLSearchParams({project})
return this.http.get(`${this.urlGoogleStorage}?${qs.toString()}`, { headers: {Authorization: `Bearer ${accessToken}`}}).pipe(
catchError((error) => {
if(error.status == 401) this.auth.updateAccessToken(account);
return throwError(() => error)
})
)
}
Is there a more efficient way to handle access token expiration and renewal across multiple APIs?