Skip to content

Commit

Permalink
fix(fresh_dio): remove _httpClient lock and add token into headers (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
rtviwe committed Apr 26, 2021
1 parent 91ed791 commit f2e5feb
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions packages/fresh_dio/lib/src/fresh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ class Fresh<T> extends Interceptor with FreshMixin<T> {
Future<Response<dynamic>> _tryRefresh(Response response) async {
late final T refreshedToken;
try {
_httpClient.lock();
refreshedToken = await _refreshToken(await token, _httpClient);
} on RevokeTokenException catch (error) {
await clearToken();
Expand All @@ -134,8 +133,6 @@ class Fresh<T> extends Interceptor with FreshMixin<T> {
error: error,
response: response,
);
} finally {
_httpClient.unlock();
}

await setToken(refreshedToken);
Expand All @@ -152,7 +149,8 @@ class Fresh<T> extends Interceptor with FreshMixin<T> {
sendTimeout: response.requestOptions.sendTimeout,
receiveTimeout: response.requestOptions.receiveTimeout,
extra: response.requestOptions.extra,
headers: response.requestOptions.headers,
headers: response.requestOptions.headers
..addAll(_tokenHeader(refreshedToken)),
responseType: response.requestOptions.responseType,
contentType: response.requestOptions.contentType,
validateStatus: response.requestOptions.validateStatus,
Expand All @@ -170,4 +168,4 @@ class Fresh<T> extends Interceptor with FreshMixin<T> {
static bool _defaultShouldRefresh(Response? response) {
return response?.statusCode == 401;
}
}
}

0 comments on commit f2e5feb

Please sign in to comment.