When a user purchases a subscription we run the code that calls purchase()
:
const getInfo = useCallback(async () => {
try {
const info = await Purchases.getCustomerInfo();
packageRef.current =
info?.entitlements?.active?.[entitlementName]?.productIdentifier;
const { isActive: isEntitled } =
info?.entitlements?.active?.[entitlementName] || {};
setIsActive(!!isEntitled);
if (isEntitled) {
setSawPaywall(true);
}
return info;
} catch (e) {
throw new Error((e as Error).message);
}
}, [setIsActive]);
const purchase = async (purchasePackage: PurchasesPackage) => {
try {
await Purchases.purchasePackage(purchasePackage);
await getInfo();
} catch (e) {
if ((e as Error).message !== 'Purchase was cancelled.') {
throw new Error((e as Error).message);
}
}
};
After the subscription is successful, the app runs correctly, which navigates to the sign in page and after the user signs in, goes to our home view.
Then, if I quit the app and go back in, the paywall comes back up again. Instead it should go to the home view.
I have traced this to an issue with the info?.entitlements?.active?.[entitlementName].isActive
part of the response of getCustomerInfo
: it is returning false.
So I press “restore purchase” and the app functions fine after that.
What is causing isActive
to be false yet the restore purchase updates. I know there’s a cache on getCustomerInfo