Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
fix(interceptor): fix automatic refresh token usage
Browse files Browse the repository at this point in the history
usually the token gets refreshed before, so most did requests never got there anyways
  • Loading branch information
doktordirk committed Nov 17, 2016
1 parent bdf4384 commit 62d61de
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/fetchClientConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,24 @@ export class FetchConfig {
},
response: (response, request) => {
return new Promise((resolve, reject) => {
// resolve success
if (response.ok) {
return resolve(response);
}
// resolve all non-authorization errors
if (response.status !== 401) {
return resolve(response);
}
// resolve unexpected authorization errors (not a managed request or token not expired)
if (!this.config.httpInterceptor || !this.authService.isTokenExpired()) {
return resolve(response);
}
// resolve expected authorization error without refresh_token setup
if (!this.config.useRefreshToken || !this.authService.getRefreshToken()) {
return resolve(response);
}

// refresh token and try again
return this.authService.updateToken().then(() => {
let token = this.authService.getAccessToken();

Expand All @@ -66,7 +71,7 @@ export class FetchConfig {

request.headers.set(this.config.authHeader, token);

return this.client.fetch(request).then(resolve);
return this.httpClient.fetch(request).then(resolve);
});
});
}
Expand Down

0 comments on commit 62d61de

Please sign in to comment.