fresh_dio
0.6.0, released 9 months ago by felangel.dev
A dio interceptor for automatic token refresh and authentication management.
What it does
Fresh is an HTTP interceptor built on top of package:dio that manages authentication tokens transparently. It automatically refreshes expired tokens, attaches auth headers, handles 401 errors by retrying requests, and provides an authentication status stream.
AI-written summary of version 0.6.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You are using dio for networking and need automatic token refresh on 401 responses.
- You need single-flight request queuing during token refresh.
- You want to react to authentication status changes via a stream.
Skip it when
- Not documented
- You are not using package:dio for your networking layer.
Strengths
- Automatic token refresh and proactive refreshing before requests
- Single-flight refresh prevents duplicate concurrent refresh calls
- Pluggable token storage and custom token formats supported
Weaknesses
- Tied specifically to package:dio
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 2
final dio = Dio();
dio.interceptors.add(
Fresh.oAuth2(
tokenStorage: InMemoryTokenStorage<OAuth2Token>(),
refreshToken: (token, client) async {
final response = await client.post(
'https://api.example.com/auth/refresh',
data: {'refresh_token': token?.refreshToken},
);
final body = response.data as Map<String, dynamic>;
return OAuth2Token(
accessToken: body['access_token'],
refreshToken: body['refresh_token'],
);
},
),
);Alternatives
Packages that do the same job and could replace fresh_dio.
- http2
An HTTP/2 implementation in Dart for low-level transport and pooled HTTP/2 requests.
91Compare - dio_web_adapter
Web and WASM HTTP client adapter for Dio.
83Compare - dio_cache_interceptor
Dio HTTP cache interceptor with multiple stores respecting HTTP directives.
87Compare - dio_refresh
Dio interceptor for automatic token refresh and retry on API failures
74Compare
Works with
Packages commonly used together with fresh_dio: ones it builds on, ones built on it, and its own family.
- diofresh_dio depends on itA powerful HTTP networking package for Dart and Flutter with interceptors and request cancellation.
- freshfresh_dio depends on itCore token refresh library for managing authentication token lifecycles.
- fresh_httpSame familyAn http.Client wrapper that automatically refreshes authentication tokens and retries requests.
- fresh_graphqlSame familyA GraphQL link for package:graphql that manages authentication tokens transparently.