removeIdentity method

Future removeIdentity(
  1. Map<String, dynamic> parameters
)

Implementation

Future<dynamic> removeIdentity(Map<String, dynamic> parameters) async {
  final itemMap = parameters['item'] as Map<String, dynamic>;
  final namespace = parameters['namespace'] as String;

  try {
    AuthenticatedState authState;
    switch (itemMap['authenticatedState'] as String) {
      case 'authenticated':
        authState = AuthenticatedState.AUTHENTICATED;
        break;
      case 'ambiguous':
        authState = AuthenticatedState.AMBIGUOUS;
        break;
      case 'loggedOut':
        authState = AuthenticatedState.LOGGED_OUT;
        break;
      default:
        authState = AuthenticatedState.AMBIGUOUS;
    }

    final item = IdentityItem(
      itemMap['id'] as String,
      authState,
      itemMap['primary'] as bool? ?? false,
    );
    // Perform the removal with a timeout
    try {
      final removeFuture = Identity.removeIdentity(item, namespace);
      final timeoutFuture = Future.delayed(Duration(seconds: 1));
      await Future.any([removeFuture, timeoutFuture]);
      final afterRemovalIdentities = await Identity.identities;
      return afterRemovalIdentities;
    } catch (e) {
      print('Error during identity removal: $e');
      throw StateError('Failed to remove identity: $e');
    }
  } catch (e) {
    print('Error in removeIdentity: $e');
    debugPrint('Error in identity removal process: $e');
    throw StateError('Error in identity removal process: $e');
  }
}