revokeToken static method

Future<Map<String, Object?>> revokeToken(
  1. Client cloudApiClient, {
  2. required String tokenId,
  3. required String localStoragePath,
})

Implementation

static Future<Map<String, Object?>> revokeToken(
  final Client cloudApiClient, {
  required final String tokenId,
  required final String localStoragePath,
}) async {
  final bool currentSessionRevoked;
  try {
    currentSessionRevoked = await cloudApiClient.authWithAuth.logoutDevice(
      authTokenId: tokenId,
    );
  } on NotFoundException catch (e) {
    throw FailureException(error: e.message);
  } on Exception catch (e, s) {
    throw FailureException.nested(e, s, 'Failed to revoke token');
  }

  if (currentSessionRevoked) {
    try {
      await ResourceManager.removeServerpodCloudAuthData(
        localStoragePath: localStoragePath,
      );
    } on Exception catch (e, s) {
      throw FailureException.nested(
        e,
        s,
        'Failed to remove stored credentials',
        'Please remove these manually. '
            'They should be located in $localStoragePath.',
      );
    }
  }

  return {'currentSessionRevoked': currentSessionRevoked};
}