linkExternalId method

Future<bool> linkExternalId(
  1. String externalId
)

Links an external user ID to the current device subscription.

This is useful for cross-platform identification of the same user. The external ID can be any string that uniquely identifies the user in your system.

Parameters:

  • externalId: The external identifier to associate with this device

Example:

await SuperFCM.instance.linkExternalId('user_123');

Implementation

Future<bool> linkExternalId(String externalId) async {
  return _queueOrExecute("linkExternalId", () async {
    logger.i('Linking external ID: $externalId');

    if (subscription?.externalId == externalId) {
      logger.v('External ID already linked');
      return true;
    }

    final response = await _patch('subscriptions/${subscription!.id}', {
      'externalId': externalId,
    });

    return _handleResponse(
      response,
      'link external ID',
      onSuccess: (response) {
        subscription = subscription!.copyWith(externalId: externalId);
        _storeSubscription();
      },
    );
  });
}