@umituz/react-native-subscription 2.37.57 → 2.37.59

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.57",
3
+ "version": "2.37.59",
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",
@@ -11,6 +11,7 @@ export async function startBackgroundInitialization(config: SubscriptionInitConf
11
11
  let retryTimer: ReturnType<typeof setTimeout> | null = null;
12
12
  let lastUserId: string | undefined = undefined;
13
13
  let lastInitSucceeded = false;
14
+ let isInitializing = false; // true while attemptInitWithRetry is awaited
14
15
 
15
16
  const initializeInBackground = async (revenueCatUserId?: string): Promise<void> => {
16
17
  if (typeof __DEV__ !== 'undefined' && __DEV__) {
@@ -65,7 +66,7 @@ export async function startBackgroundInitialization(config: SubscriptionInitConf
65
66
  retryTimer = null;
66
67
  }
67
68
 
68
- if (lastUserId === revenueCatUserId && lastInitSucceeded) {
69
+ if (lastUserId === revenueCatUserId && (lastInitSucceeded || isInitializing)) {
69
70
  if (typeof __DEV__ !== 'undefined' && __DEV__) {
70
71
  console.log('[BackgroundInitializer] UserId unchanged and init succeeded, skipping');
71
72
  }
@@ -83,7 +84,12 @@ export async function startBackgroundInitialization(config: SubscriptionInitConf
83
84
  lastInitSucceeded = false;
84
85
  }
85
86
 
86
- void attemptInitWithRetry(revenueCatUserId);
87
+ isInitializing = true;
88
+ try {
89
+ await attemptInitWithRetry(revenueCatUserId);
90
+ } finally {
91
+ isInitializing = false;
92
+ }
87
93
  }, AUTH_STATE_DEBOUNCE_MS);
88
94
  };
89
95
 
@@ -68,6 +68,10 @@ export function configureServices(config: SubscriptionInitConfig, apiKey: string
68
68
  const u = auth.currentUser;
69
69
  return !!(u && !u.isAnonymous);
70
70
  },
71
+ hasFirebaseUser: () => {
72
+ const auth = getFirebaseAuth();
73
+ return !!(auth?.currentUser);
74
+ },
71
75
  showAuthModal,
72
76
  });
73
77
 
@@ -3,6 +3,7 @@ import type { PurchaseSource } from "../../core/SubscriptionConstants";
3
3
 
4
4
  export interface PurchaseAuthProvider {
5
5
  isAuthenticated: () => boolean;
6
+ hasFirebaseUser: () => boolean;
6
7
  showAuthModal: () => void;
7
8
  }
8
9
 
@@ -54,10 +54,10 @@ export const useAuthAwarePurchase = (
54
54
  const authProvider = authPurchaseStateManager.getProvider();
55
55
  if (!authProvider) return;
56
56
 
57
- const isAuth = authProvider.isAuthenticated();
57
+ const hasUser = authProvider.hasFirebaseUser();
58
58
  const hasSavedPurchase = !!authPurchaseStateManager.getSavedPurchase();
59
59
 
60
- if (isAuth && hasSavedPurchase && !isExecutingSavedRef.current) {
60
+ if (hasUser && hasSavedPurchase && !isExecutingSavedRef.current) {
61
61
  isExecutingSavedRef.current = true;
62
62
  executeSavedPurchase().finally(() => {
63
63
  isExecutingSavedRef.current = false;
@@ -73,9 +73,7 @@ export const useAuthAwarePurchase = (
73
73
  return false;
74
74
  }
75
75
 
76
- const isAuth = authProvider.isAuthenticated();
77
-
78
- if (!isAuth) {
76
+ if (!authProvider.hasFirebaseUser()) {
79
77
  authPurchaseStateManager.savePurchase(pkg, source || params?.source || "settings");
80
78
  authProvider.showAuthModal();
81
79
  return false;
@@ -95,7 +93,7 @@ export const useAuthAwarePurchase = (
95
93
  return false;
96
94
  }
97
95
 
98
- if (!authProvider.isAuthenticated()) {
96
+ if (!authProvider.hasFirebaseUser()) {
99
97
  authProvider.showAuthModal();
100
98
  return false;
101
99
  }