fresh
0.7.0, released 9 days ago by felangel.dev
Core token refresh library for managing authentication token lifecycles.
What it does
Exposes core components common to various token refresh implementations such as REST or GraphQL. Provides token lifecycle management, single-flight refresh coordination, and stream-based authentication state tracking.
AI-written summary of version 0.7.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You are building a custom HTTP client integration that requires token refresh logic.
- You need to coordinate concurrent refresh attempts to share a single in-flight operation.
Skip it when
- You are using standard clients like Dio or the http package (use fresh_dio or fresh_http integration packages instead).
- You do not need token refresh functionality.
Strengths
- Single-flight refresh coordination prevents duplicate concurrent refresh requests.
- Stream-based authentication status tracking.
- Extensible token base class and custom storage support.
Weaknesses
- Most users must rely on separate integration packages for standard clients.
- Requires writing custom boilerplate if building a non-standard integration.
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 1
Not documented
class MyHttpFresh extends MyHttpClient with FreshMixin<OAuth2Token> {
MyHttpFresh({required TokenStorage<OAuth2Token> tokenStorage}) {
this.tokenStorage = tokenStorage;
}
@override
Future<OAuth2Token> performTokenRefresh(OAuth2Token? token) async {
final response = await post('/auth/refresh', body: {'refresh_token': token?.refreshToken});
return OAuth2Token(
accessToken: response['access_token'],
refreshToken: response['refresh_token'],
);
}
}Alternatives
Packages that do the same job and could replace fresh.
- amplify_api
Amplify Flutter API plugin supporting GraphQL and REST operations.
89Compare - amplify_api_dart
Dart-only Amplify API plugin for GraphQL and REST.
84Compare - dash_kit_network
Dio-based networking client for Flutter with built-in token refresh management.
75Compare - socket_io_common
Socket.io common parser library for Dart.
47Compare
Works with
Packages commonly used together with fresh: ones it builds on, ones built on it, and its own family.
- fresh_httpBuilt on freshAn http.Client wrapper that automatically refreshes authentication tokens and retries requests.
- fresh_dioBuilt on freshA dio interceptor for automatic token refresh and authentication management.
- fresh_graphqlBuilt on freshA GraphQL link for package:graphql that manages authentication tokens transparently.