@umituz/react-native-subscription 2.13.9 → 2.13.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-subscription",
|
|
3
|
-
"version": "2.13.
|
|
3
|
+
"version": "2.13.11",
|
|
4
4
|
"description": "Complete subscription management with RevenueCat, paywall UI, and credits system for React Native apps",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Auth-Aware Purchase Hook
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Uses globally configured auth provider
|
|
4
|
+
* Configure once at app start with configureAuthProvider()
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { useCallback } from "react";
|
|
@@ -13,52 +13,78 @@ export interface PurchaseAuthProvider {
|
|
|
13
13
|
showAuthModal: () => void;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
// Global auth provider - configured once at app start
|
|
17
|
+
let globalAuthProvider: PurchaseAuthProvider | null = null;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Configure auth provider for purchases
|
|
21
|
+
* Call this once at app initialization
|
|
22
|
+
*/
|
|
23
|
+
export const configureAuthProvider = (provider: PurchaseAuthProvider): void => {
|
|
24
|
+
globalAuthProvider = provider;
|
|
25
|
+
if (__DEV__) {
|
|
26
|
+
console.log("[useAuthAwarePurchase] Auth provider configured");
|
|
27
|
+
}
|
|
28
|
+
};
|
|
19
29
|
|
|
20
30
|
export interface UseAuthAwarePurchaseResult {
|
|
21
31
|
handlePurchase: (pkg: PurchasesPackage) => Promise<boolean>;
|
|
22
32
|
handleRestore: () => Promise<boolean>;
|
|
23
33
|
}
|
|
24
34
|
|
|
25
|
-
export const useAuthAwarePurchase = ({
|
|
26
|
-
authProvider,
|
|
27
|
-
}: UseAuthAwarePurchaseParams): UseAuthAwarePurchaseResult => {
|
|
35
|
+
export const useAuthAwarePurchase = (): UseAuthAwarePurchaseResult => {
|
|
28
36
|
const { purchasePackage, restorePurchase, closePaywall } = usePremium();
|
|
29
37
|
|
|
30
38
|
const handlePurchase = useCallback(
|
|
31
39
|
async (pkg: PurchasesPackage): Promise<boolean> => {
|
|
32
|
-
if (!
|
|
40
|
+
if (!globalAuthProvider) {
|
|
41
|
+
if (__DEV__) {
|
|
42
|
+
console.warn(
|
|
43
|
+
"[useAuthAwarePurchase] Auth provider not configured. Call configureAuthProvider() at app start.",
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
return purchasePackage(pkg);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (!globalAuthProvider.isAuthenticated()) {
|
|
33
50
|
if (__DEV__) {
|
|
34
51
|
console.log(
|
|
35
52
|
"[useAuthAwarePurchase] User not authenticated, opening auth modal",
|
|
36
53
|
);
|
|
37
54
|
}
|
|
38
55
|
closePaywall();
|
|
39
|
-
|
|
56
|
+
globalAuthProvider.showAuthModal();
|
|
40
57
|
return false;
|
|
41
58
|
}
|
|
42
59
|
|
|
43
60
|
return purchasePackage(pkg);
|
|
44
61
|
},
|
|
45
|
-
[purchasePackage, closePaywall
|
|
62
|
+
[purchasePackage, closePaywall],
|
|
46
63
|
);
|
|
47
64
|
|
|
48
65
|
const handleRestore = useCallback(async (): Promise<boolean> => {
|
|
49
|
-
if (!
|
|
66
|
+
if (!globalAuthProvider) {
|
|
67
|
+
if (__DEV__) {
|
|
68
|
+
console.warn(
|
|
69
|
+
"[useAuthAwarePurchase] Auth provider not configured. Call configureAuthProvider() at app start.",
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
return restorePurchase();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!globalAuthProvider.isAuthenticated()) {
|
|
50
76
|
if (__DEV__) {
|
|
51
77
|
console.log(
|
|
52
78
|
"[useAuthAwarePurchase] User not authenticated, opening auth modal",
|
|
53
79
|
);
|
|
54
80
|
}
|
|
55
81
|
closePaywall();
|
|
56
|
-
|
|
82
|
+
globalAuthProvider.showAuthModal();
|
|
57
83
|
return false;
|
|
58
84
|
}
|
|
59
85
|
|
|
60
86
|
return restorePurchase();
|
|
61
|
-
}, [restorePurchase, closePaywall
|
|
87
|
+
}, [restorePurchase, closePaywall]);
|
|
62
88
|
|
|
63
89
|
return {
|
|
64
90
|
handlePurchase,
|