@umituz/react-native-subscription 2.37.59 → 2.37.60

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.37.59",
3
+ "version": "2.37.60",
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",
@@ -1,6 +1,6 @@
1
1
  import { useQuery, useQueryClient } from "@umituz/react-native-design-system";
2
2
  import { useCallback, useMemo, useEffect } from "react";
3
- import { useAuthStore, selectUserId, selectIsAnonymous } from "@umituz/react-native-auth";
3
+ import { useAuthStore, selectUserId } from "@umituz/react-native-auth";
4
4
  import { subscriptionEventBus, SUBSCRIPTION_EVENTS } from "../../../shared/infrastructure/SubscriptionEventBus";
5
5
  import { NO_CACHE_QUERY_CONFIG } from "../../../shared/infrastructure/react-query/queryConfig";
6
6
  import { usePreviousUserCleanup } from "../../../shared/infrastructure/react-query/hooks/usePreviousUserCleanup";
@@ -10,7 +10,7 @@ import {
10
10
  isCreditsRepositoryConfigured,
11
11
  } from "../infrastructure/CreditsRepositoryManager";
12
12
  import { calculateSafePercentage, canAffordAmount } from "../utils/creditValidation";
13
- import { isRegisteredUser } from "../../subscription/utils/authGuards";
13
+ import { isAuthenticated } from "../../subscription/utils/authGuards";
14
14
  import { creditsQueryKeys } from "./creditsQueryKeys";
15
15
  import type { UseCreditsResult, CreditsLoadStatus } from "./useCredits.types";
16
16
 
@@ -26,17 +26,16 @@ const deriveLoadStatus = (
26
26
 
27
27
  export const useCredits = (): UseCreditsResult => {
28
28
  const userId = useAuthStore(selectUserId);
29
- const isAnonymous = useAuthStore(selectIsAnonymous);
30
29
  const isConfigured = isCreditsRepositoryConfigured();
31
30
 
32
31
  const config = isConfigured ? getCreditsConfig() : null;
33
- const isUserRegistered = isRegisteredUser(userId, isAnonymous);
34
- const queryEnabled = isUserRegistered && isConfigured;
32
+ const hasUser = isAuthenticated(userId);
33
+ const queryEnabled = hasUser && isConfigured;
35
34
 
36
35
  const { data, status, error, refetch } = useQuery({
37
36
  queryKey: creditsQueryKeys.user(userId),
38
37
  queryFn: async () => {
39
- if (!isUserRegistered || !isConfigured) return null;
38
+ if (!hasUser || !isConfigured) return null;
40
39
 
41
40
  const repository = getCreditsRepository();
42
41
  const result = await repository.getCredits(userId);
@@ -56,7 +55,7 @@ export const useCredits = (): UseCreditsResult => {
56
55
  usePreviousUserCleanup(userId, queryClient, creditsQueryKeys.user);
57
56
 
58
57
  useEffect(() => {
59
- if (!isUserRegistered) return undefined;
58
+ if (!hasUser) return undefined;
60
59
 
61
60
  const unsubscribe = subscriptionEventBus.on(SUBSCRIPTION_EVENTS.CREDITS_UPDATED, (updatedUserId) => {
62
61
  if (updatedUserId === userId) {
@@ -65,7 +64,7 @@ export const useCredits = (): UseCreditsResult => {
65
64
  });
66
65
 
67
66
  return unsubscribe;
68
- }, [userId, isUserRegistered, queryClient]);
67
+ }, [userId, hasUser, queryClient]);
69
68
 
70
69
  const credits = data ?? null;
71
70
 
@@ -4,7 +4,6 @@ import { useAlert } from "@umituz/react-native-design-system";
4
4
  import {
5
5
  useAuthStore,
6
6
  selectUserId,
7
- selectIsAnonymous,
8
7
  } from "@umituz/react-native-auth";
9
8
  import { SubscriptionManager } from "../../infrastructure/managers/SubscriptionManager";
10
9
  import { SUBSCRIPTION_QUERY_KEYS } from "./subscriptionQueryKeys";
@@ -19,7 +18,6 @@ interface PurchaseMutationResult {
19
18
 
20
19
  export const usePurchasePackage = () => {
21
20
  const userId = useAuthStore(selectUserId);
22
- const isAnonymous = useAuthStore(selectIsAnonymous);
23
21
  const queryClient = useQueryClient();
24
22
  const { showSuccess, showError } = useAlert();
25
23
 
@@ -29,10 +27,6 @@ export const usePurchasePackage = () => {
29
27
  throw new Error("User not authenticated");
30
28
  }
31
29
 
32
- if (isAnonymous) {
33
- throw new Error("Anonymous users cannot purchase subscriptions");
34
- }
35
-
36
30
  const productId = pkg.product.identifier;
37
31
  if (typeof __DEV__ !== "undefined" && __DEV__) {
38
32
  console.log(`[Purchase] Initializing and purchasing. User: ${userId}`);