@umituz/react-native-auth 3.5.1 → 3.5.2

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-auth",
3
- "version": "3.5.1",
3
+ "version": "3.5.2",
4
4
  "description": "Authentication service for React Native apps - Secure, type-safe, and production-ready. Provider-agnostic design with dependency injection, configurable validation, and comprehensive error handling.",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -144,22 +144,26 @@ export async function initializeAuth(
144
144
  const isCurrentlyAnonymous = user.isAnonymous ?? false;
145
145
 
146
146
  // Detect anonymous-to-authenticated conversion
147
- if (
148
- previousUserId &&
149
- previousUserId !== currentUserId &&
150
- wasAnonymous &&
151
- !isCurrentlyAnonymous &&
152
- onUserConverted
153
- ) {
147
+ // This happens in two scenarios:
148
+ // 1. linkWithCredential: same UID, but isAnonymous changes from true to false
149
+ // 2. New account after anonymous: different UID (legacy flow)
150
+ const isConversionSameUser = previousUserId === currentUserId && wasAnonymous && !isCurrentlyAnonymous;
151
+ const isConversionNewUser = previousUserId && previousUserId !== currentUserId && wasAnonymous && !isCurrentlyAnonymous;
152
+ const isConversion = isConversionSameUser || isConversionNewUser;
153
+
154
+ if (isConversion && onUserConverted) {
154
155
  try {
155
- await onUserConverted(previousUserId, currentUserId);
156
+ await onUserConverted(previousUserId!, currentUserId);
156
157
  } catch {
157
158
  // Migration failed but don't block user flow
158
159
  }
159
160
  }
160
161
 
161
- // Create/update user document in Firestore
162
- await ensureUserDocument(user);
162
+ // Create/update user document in Firestore with conversion info
163
+ const extras = isConversion
164
+ ? { previousAnonymousUserId: previousUserId! }
165
+ : undefined;
166
+ await ensureUserDocument(user, extras);
163
167
 
164
168
  // Update tracking state
165
169
  previousUserId = currentUserId;