How the new authentication system works in v7
masterVersion 7 introduces support for anonymous users by default.
Anonymous Users
- You can now display products and perform purchases without calling
loginfirst. - If a user is not logged in, IAPHUB automatically generates an anonymous user ID (prefixed with
a:). - Security Note: Anonymous purchases are disabled by default. To allow them, set
allowAnonymousPurchase: truein the options of thestartmethod. - Automatic Transfer: If an anonymous user later calls
login, their previous purchases are automatically transferred to their new user ID.
Manual Migration for Device ID Users
If you previously used a device ID (e.g., from react-native-device-info) to authenticate users in production, those subscriptions are tied to that device ID. To ensure a smooth transition without forcing a restore:
- Call
login(deviceId)using the existing device ID. This prevents the user from getting a new ID. - Alternatively, ask users to call the
restore()method. This will automatically transfer purchases owned by the device ID to the new anonymous or logged-in user ID.
// Enabling anonymous purchases during initialization
await IAPHub.start({
allowAnonymousPurchase: true
});
// Logging in a user
await IAPHub.login('user_id_or_device_id');
// Logging out
await IAPHub.logout();
// Restoring purchases to migrate from device ID to new ID
await IAPHub.restore();