@umituz/react-native-subscription 2.26.10 → 2.26.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.26.
|
|
3
|
+
"version": "2.26.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",
|
|
@@ -43,6 +43,8 @@ export interface CreditsCacheConfig {
|
|
|
43
43
|
export interface UseCreditsParams {
|
|
44
44
|
userId: string | undefined;
|
|
45
45
|
enabled?: boolean;
|
|
46
|
+
/** Whether user is anonymous. Anonymous users don't get free credits. */
|
|
47
|
+
isAnonymous?: boolean;
|
|
46
48
|
/** Cache configuration. Default: 30 second staleTime, 5 minute gcTime */
|
|
47
49
|
cache?: CreditsCacheConfig;
|
|
48
50
|
}
|
|
@@ -61,6 +63,7 @@ export interface UseCreditsResult {
|
|
|
61
63
|
export const useCredits = ({
|
|
62
64
|
userId,
|
|
63
65
|
enabled = true,
|
|
66
|
+
isAnonymous = false,
|
|
64
67
|
cache,
|
|
65
68
|
}: UseCreditsParams): UseCreditsResult => {
|
|
66
69
|
const isConfigured = isCreditsRepositoryConfigured();
|
|
@@ -112,14 +115,16 @@ export const useCredits = ({
|
|
|
112
115
|
useEffect(() => {
|
|
113
116
|
// Only run if:
|
|
114
117
|
// 1. Query has completed (isFetched)
|
|
115
|
-
// 2. User is authenticated
|
|
118
|
+
// 2. User is authenticated (not anonymous)
|
|
116
119
|
// 3. No credits data exists
|
|
117
120
|
// 4. Free credits configured
|
|
118
121
|
// 5. Auto-init enabled
|
|
119
122
|
// 6. Haven't already attempted for this user (global tracking)
|
|
123
|
+
// 7. User is NOT anonymous (anonymous users must register first)
|
|
120
124
|
if (
|
|
121
125
|
isFetched &&
|
|
122
126
|
userId &&
|
|
127
|
+
!isAnonymous &&
|
|
123
128
|
isConfigured &&
|
|
124
129
|
!credits &&
|
|
125
130
|
autoInit &&
|
|
@@ -129,7 +134,7 @@ export const useCredits = ({
|
|
|
129
134
|
freeCreditsInitAttempted.add(userId);
|
|
130
135
|
|
|
131
136
|
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
132
|
-
console.log("[useCredits] Auto-initializing free credits for new user:", userId.slice(0, 8));
|
|
137
|
+
console.log("[useCredits] Auto-initializing free credits for new registered user:", userId.slice(0, 8));
|
|
133
138
|
}
|
|
134
139
|
|
|
135
140
|
const repository = getCreditsRepository();
|
|
@@ -145,8 +150,12 @@ export const useCredits = ({
|
|
|
145
150
|
}
|
|
146
151
|
}
|
|
147
152
|
});
|
|
153
|
+
} else if (isFetched && userId && isAnonymous && !credits && autoInit) {
|
|
154
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
155
|
+
console.log("[useCredits] Skipping free credits for anonymous user - registration required");
|
|
156
|
+
}
|
|
148
157
|
}
|
|
149
|
-
}, [isFetched, userId, isConfigured, credits, autoInit, refetch]);
|
|
158
|
+
}, [isFetched, userId, isAnonymous, isConfigured, credits, autoInit, refetch]);
|
|
150
159
|
|
|
151
160
|
// Memoize derived values to prevent unnecessary re-renders
|
|
152
161
|
const derivedValues = useMemo(() => {
|
|
@@ -182,9 +191,10 @@ export const useCredits = ({
|
|
|
182
191
|
};
|
|
183
192
|
|
|
184
193
|
export const useHasCredits = (
|
|
185
|
-
userId: string | undefined
|
|
194
|
+
userId: string | undefined,
|
|
195
|
+
isAnonymous?: boolean
|
|
186
196
|
): boolean => {
|
|
187
|
-
const { credits } = useCredits({ userId });
|
|
197
|
+
const { credits } = useCredits({ userId, isAnonymous });
|
|
188
198
|
if (!credits) return false;
|
|
189
199
|
return credits.credits > 0;
|
|
190
200
|
};
|