clearUserId method

Future<bool> clearUserId()

Clears the stored user ID, effectively resetting the user identity.

This method removes the user ID from persistent storage. The next call to getUserId will generate a new UUID. This is useful for:

  • Testing scenarios
  • Privacy-focused user reset functionality
  • Debugging and development

Warning: This action cannot be undone. All data associated with the previous user ID will become orphaned.

Returns true if the user ID was successfully removed, false if no user ID was stored.

Example:

final wasCleared = await userService.clearUserId();
if (wasCleared) {
  print('User ID cleared successfully');
}

// Next call will generate a new ID
final newUserId = await userService.getUserId();

Implementation

Future<bool> clearUserId() async {
  final existed = _prefs.containsKey(_userIdKey);
  await _prefs.remove(_userIdKey);
  if (existed) {
    print('User ID cleared from storage');
  }
  return existed;
}