b8ne / react-native-pusher-push-notifications

Manage pusher interest subscriptions and notification events in Javascript.
MIT License
97 stars 85 forks source link

setUserId seems to require a token parameter #76

Open daveslutzkin opened 3 years ago

daveslutzkin commented 3 years ago

setUserId has the signature:

setUserId: (userId, token, onError, onSuccess)

but nothing in the library returns the device token (which I assume is what that is)?

If that's required then the library should presumably return the token in the registered callback?

The appropriate code would be something like:

- (void)setDeviceToken:(NSData *)deviceToken
{
    RCTLogInfo(@"setDeviceToken: %@", deviceToken);
    [[PushNotifications shared] registerDeviceToken:deviceToken];
    [RNPusherEventHelper emitEventWithName:@"registered" andPayload:@{
      @"deviceToken":deviceToken
    }];
    RCTLogInfo(@"REGISTERED!");
}
gabrielbezerra81 commented 2 years ago

The server SDK libraries have a function that generates this token. In our app, I pass the user_uuid attribute to an API request and it gives me back the generated pusher token. Then I call setUserId with these two parameters to bind the logged user.