IAuthRefreshHandler class abstract

Interface for handling authentication token refresh logic.

Implement this interface to provide custom refresh behavior.

Example:

class MyAuthHandler implements IAuthRefreshHandler {
  @override
  bool shouldRefresh(DioException err) {
    return err.response?.statusCode == 401;
  }

  @override
  Future<String> refreshToken() async {
    final response = await myAuthService.refresh();
    return response.accessToken;
  }

  @override
  void setAuthHeader(RequestOptions req, String accessToken) {
    req.headers['Authorization'] = 'Bearer $accessToken';
  }

  @override
  void onRefreshSuccess(String newToken) {
    // Optional: save token to storage
    secureStorage.write('access_token', newToken);
  }

  @override
  void onRefreshError(dynamic error) {
    // Optional: handle refresh failure (e.g., logout user)
    authService.logout();
  }
}
Implementers

Constructors

IAuthRefreshHandler()

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onRefreshError(dynamic error) → void
Called when token refresh fails.
onRefreshSuccess(String newToken) → void
Called after a successful token refresh.
refreshToken() → Future<String>
Performs the token refresh operation.
setAuthHeader(RequestOptions req, String accessToken) → void
Sets the authorization header on the request using the provided token.
shouldRefresh(DioException err) → bool
Determines if the error should trigger a token refresh.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited