iaphub / react-native-iaphub

The easiest way to implement IAP (In-app purchase) in your React Native app.
https://www.iaphub.com/
MIT License
319 stars 22 forks source link

Get anonymous user ID on device #128

Closed flogy closed 1 year ago

flogy commented 1 year ago

Hi there,

Is it possible to get the generated anonymous user Id on the device? This would be helpful as I currently have a server backend that checks whether a certain user is eligible for pro user functionality or not. This is done via user API which requires the user ID.

Thanks in advance!

iaphub commented 1 year ago

Hi @flogy.

It is not possible right now but we could definitely add a method to retrieve the user ID. If I'm understanding correctly you're calling your server (that is calling the IAPHUB user API) in order to know if you should display a Pro membership? What are you checking on the IAPHUB user API to determine if a user is eligible?

flogy commented 1 year ago

Okay, thanks for the quick reply!

To explain in more detail:

Users can create rooms and those rooms can be upgraded to pro. A room is upgraded to pro if the creator bought a one-time purchase or has an active subscription. Other users will also see if a room is pro or not.

Therefore I built a mechanism that checks if a room is pro or not on server-side to make it more secure. To do so, it will ask the IAPHUB API to get the latest purchases (to check for one-time payment) using https://api.iaphub.com/v1/app/${appId}/purchase/${purchaseId} or get the user's active products (to check for active subscriptions) using https://api.iaphub.com/v1/app/${appId}/user/${userId}?platform=${platform}.

That's why I require the user ID. Currently, I'm still using a custom user ID that is the device ID. But now as I migrated to the latest version of this library I thought it would be nice to migrate the user IDs too.

iaphub commented 1 year ago

Ok I see, even though I would recommend to sync your server using webhooks for an even safer & cleaner implementation.

But otherwise adding a method getUserId to return the id of the current user would be indeed useful. We're going to add the method. Hopefully we can ship it in a new release by the end of the week.

I'm closing the issue but I'll comment the thread when we deploy the new release.

iaphub commented 1 year ago

You can now use the getUserId method available in the latest release (8.2.1) 🙂