setUserId method

  1. @override
Future<void> setUserId(
  1. String userId,
  2. BeamsAuthProvider provider,
  3. OnUserCallback callback
)
override

Sets authentication for this device, so you can send notifications specifically for this device. You must create a BeamsAuthProvider in order to pass the provider argument.

Example Usage

function someAsyncFunction() async {
  final BeamsAuthProvider provider = BeamsAuthProvider()
    ..authUrl = 'https://some-auth-url.com/secure'
    ..headers = {
      'Content-Type': 'application/json'
    }
    ..queryParams = {
      'page': '1'
    }
    ..credentials = 'omit';

  await PusherBeams.instance.setUserId('THIS IS AN USER ID', provider, (error) => {
    if (error != null) {
      print(error)
    }

    // Success! Do something...
  });
}

BeamsAuthProvider

This is the list parameters table which describes the class to creates a provider.

Parameter Description Required
authUrl An HTTP url where Pusher Beams will try to authenticate. Yes
headers A Map which represents Headers sent to authUrl No
queryParams A Map which represents URL Query Params sent to authUrl No
credentials More information No

Throws an Exception in case of failure.

Implementation

@override
Future<void> setUserId(String userId, BeamsAuthProvider provider,
    OnUserCallback callback) async {
  final callbackId = _uuid.v4();

  if (!kIsWeb) {
    _callbacks[callbackId] = callback;
  }

  await _pusherBeamsApi.setUserId(
      userId, provider, kIsWeb ? callback : callbackId);
}