refreshToken method

Future<TokenResponse> refreshToken()

Refreshes the current access token using the refresh token

Returns the new token response or throws an exception if refresh fails.

Implementation

Future<TokenResponse> refreshToken() async {
  if (_currentTokens == null) {
    throw FrappeTokenException(
      'No tokens available to refresh',
      code: 'no_tokens',
    );
  }

  try {
    final newTokens = await _refreshTokens(_currentTokens!.refreshToken);
    _currentTokens = newTokens;
    return newTokens;
  } catch (e) {
    // If refresh fails, clear current tokens
    _currentTokens = null;
    _currentUser = null;
    rethrow;
  }
}