onRefreshToken method

Future<(String, String)> onRefreshToken({
  1. String oldAccessToken = '',
  2. TokensCallback? callback,
})

Implementation

Future<(String, String)> onRefreshToken({
  String oldAccessToken = '',
  TokensCallback? callback,
}) async {
  if (oldAccessToken != _authLocal.accessToken) {
    return (_authLocal.accessToken, _authLocal.refreshToken);
  }

  final Completer<(String, String)> completer = Completer<(String, String)>();
  _refreshTokenCompleters.add(completer);

  if (!_isRefreshing) {
    _isRefreshing = true;

    final (String, String) result = await _performRefreshToken(
      callback: callback,
    );

    _isRefreshing = false;
    _refreshTokenCompleters.completeAllQueue(result);
  }

  return completer.future;
}