@umituz/react-native-auth 3.6.88 → 3.6.90
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.6.
|
|
3
|
+
"version": "3.6.90",
|
|
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",
|
package/src/index.ts
CHANGED
|
@@ -51,7 +51,7 @@ export { useRequireAuth, useUserId } from './presentation/hooks/useRequireAuth';
|
|
|
51
51
|
export { useUserProfile } from './presentation/hooks/useUserProfile';
|
|
52
52
|
export type { UserProfileData, UseUserProfileParams } from './presentation/hooks/useUserProfile';
|
|
53
53
|
export { useAccountManagement } from './presentation/hooks/useAccountManagement';
|
|
54
|
-
export type { UseAccountManagementReturn } from './presentation/hooks/useAccountManagement';
|
|
54
|
+
export type { UseAccountManagementReturn, UseAccountManagementOptions } from './presentation/hooks/useAccountManagement';
|
|
55
55
|
export { useProfileUpdate } from './presentation/hooks/useProfileUpdate';
|
|
56
56
|
export type { UseProfileUpdateReturn } from './presentation/hooks/useProfileUpdate';
|
|
57
57
|
export { useProfileEdit } from './presentation/hooks/useProfileEdit';
|
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
import type { Auth, User } from "firebase/auth";
|
|
7
7
|
import { getFirebaseAuth } from "@umituz/react-native-firebase";
|
|
8
8
|
import { initializeAuthService } from "./AuthService";
|
|
9
|
+
import { configureUserDocumentService } from "./UserDocumentService";
|
|
10
|
+
import type { UserDocumentExtras } from "./UserDocumentService";
|
|
11
|
+
import { collectDeviceExtras } from "@umituz/react-native-design-system";
|
|
9
12
|
import { initializeAuthListener } from "../../presentation/stores/initializeAuthListener";
|
|
10
13
|
import { createAuthStateHandler } from "../utils/authStateHandler";
|
|
11
14
|
import type { ConversionState } from "../utils/authConversionDetector";
|
|
@@ -13,6 +16,9 @@ import type { AuthConfig } from "../../domain/value-objects/AuthConfig";
|
|
|
13
16
|
import type { IStorageProvider } from "../types/Storage.types";
|
|
14
17
|
|
|
15
18
|
export interface InitializeAuthOptions {
|
|
19
|
+
userCollection?: string;
|
|
20
|
+
extraFields?: Record<string, unknown>;
|
|
21
|
+
collectExtras?: () => Promise<UserDocumentExtras>;
|
|
16
22
|
storageProvider?: IStorageProvider;
|
|
17
23
|
autoAnonymousSignIn?: boolean;
|
|
18
24
|
onUserConverted?: (anonymousId: string, authenticatedId: string) => void | Promise<void>;
|
|
@@ -52,6 +58,9 @@ async function doInitializeAuth(
|
|
|
52
58
|
): Promise<{ success: boolean; auth: Auth | null }> {
|
|
53
59
|
|
|
54
60
|
const {
|
|
61
|
+
userCollection = "users",
|
|
62
|
+
extraFields,
|
|
63
|
+
collectExtras,
|
|
55
64
|
storageProvider,
|
|
56
65
|
autoAnonymousSignIn = true,
|
|
57
66
|
onUserConverted,
|
|
@@ -62,6 +71,12 @@ async function doInitializeAuth(
|
|
|
62
71
|
const auth = getFirebaseAuth();
|
|
63
72
|
if (!auth) return { success: false, auth: null };
|
|
64
73
|
|
|
74
|
+
configureUserDocumentService({
|
|
75
|
+
collectionName: userCollection,
|
|
76
|
+
extraFields,
|
|
77
|
+
collectExtras: collectExtras || collectDeviceExtras,
|
|
78
|
+
});
|
|
79
|
+
|
|
65
80
|
let authServiceInitFailed = false;
|
|
66
81
|
try {
|
|
67
82
|
await initializeAuthService(auth, authConfig, storageProvider);
|
|
@@ -7,10 +7,6 @@ import type { Auth, User } from "firebase/auth";
|
|
|
7
7
|
import type { AuthActions } from "../../../types/auth-store.types";
|
|
8
8
|
import { completeInitialization } from "./listenerState.util";
|
|
9
9
|
import { handleAnonymousMode } from "./anonymousHandler";
|
|
10
|
-
import {
|
|
11
|
-
createOrUpdateUserDocument,
|
|
12
|
-
getFirestoreInstance,
|
|
13
|
-
} from "../../repositories/UserDocumentRepository";
|
|
14
10
|
|
|
15
11
|
type Store = AuthActions & { isAnonymous: boolean };
|
|
16
12
|
|
|
@@ -36,14 +32,6 @@ export function handleAuthStateChange(
|
|
|
36
32
|
store.setFirebaseUser(user);
|
|
37
33
|
store.setInitialized(true);
|
|
38
34
|
|
|
39
|
-
// Create or update Firestore user document (best practice)
|
|
40
|
-
if (user) {
|
|
41
|
-
createOrUpdateUserDocument(getFirestoreInstance(), user).catch((error) => {
|
|
42
|
-
console.error("[AuthListener] Failed to create/update user document:", error);
|
|
43
|
-
// Don't throw - Firestore failures shouldn't block auth state updates
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
35
|
// Handle conversion from anonymous
|
|
48
36
|
if (user && !user.isAnonymous && store.isAnonymous) {
|
|
49
37
|
store.setIsAnonymous(false);
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* User Document Repository
|
|
3
|
-
* Manages Firestore user documents using Firebase Auth UID
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { doc, setDoc, getDoc, serverTimestamp, getFirestore } from "firebase/firestore";
|
|
7
|
-
import type { Firestore } from "firebase/firestore";
|
|
8
|
-
import type { User } from "firebase/auth";
|
|
9
|
-
import type { UserProfile } from "../../domain/entities/UserProfile";
|
|
10
|
-
|
|
11
|
-
const USERS_COLLECTION = "users";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Create or update user document in Firestore
|
|
15
|
-
* Uses Firebase Auth UID as document ID (best practice)
|
|
16
|
-
*/
|
|
17
|
-
export async function createOrUpdateUserDocument(
|
|
18
|
-
firestore: Firestore,
|
|
19
|
-
user: User
|
|
20
|
-
): Promise<void> {
|
|
21
|
-
try {
|
|
22
|
-
const userRef = doc(firestore, USERS_COLLECTION, user.uid);
|
|
23
|
-
const userDoc = await getDoc(userRef);
|
|
24
|
-
|
|
25
|
-
const userData: Partial<UserProfile> = {
|
|
26
|
-
uid: user.uid,
|
|
27
|
-
email: user.email,
|
|
28
|
-
displayName: user.displayName,
|
|
29
|
-
photoURL: user.photoURL,
|
|
30
|
-
isAnonymous: user.isAnonymous,
|
|
31
|
-
lastLoginAt: new Date(),
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
if (!userDoc.exists()) {
|
|
35
|
-
// New user - create document with createdAt
|
|
36
|
-
await setDoc(userRef, {
|
|
37
|
-
...userData,
|
|
38
|
-
createdAt: serverTimestamp(),
|
|
39
|
-
lastLoginAt: serverTimestamp(),
|
|
40
|
-
});
|
|
41
|
-
} else {
|
|
42
|
-
// Existing user - update lastLoginAt only
|
|
43
|
-
await setDoc(
|
|
44
|
-
userRef,
|
|
45
|
-
{
|
|
46
|
-
lastLoginAt: serverTimestamp(),
|
|
47
|
-
// Update these in case they changed (e.g., anonymous → registered)
|
|
48
|
-
email: userData.email,
|
|
49
|
-
displayName: userData.displayName,
|
|
50
|
-
photoURL: userData.photoURL,
|
|
51
|
-
isAnonymous: userData.isAnonymous,
|
|
52
|
-
},
|
|
53
|
-
{ merge: true }
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
} catch (error) {
|
|
57
|
-
console.error("[UserDocumentRepository] Failed to create/update user document:", error);
|
|
58
|
-
// Don't throw - allow auth to continue even if Firestore fails
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Check if user document exists
|
|
64
|
-
*/
|
|
65
|
-
export async function userDocumentExists(
|
|
66
|
-
firestore: Firestore,
|
|
67
|
-
uid: string
|
|
68
|
-
): Promise<boolean> {
|
|
69
|
-
try {
|
|
70
|
-
const userRef = doc(firestore, USERS_COLLECTION, uid);
|
|
71
|
-
const userDoc = await getDoc(userRef);
|
|
72
|
-
return userDoc.exists();
|
|
73
|
-
} catch (error) {
|
|
74
|
-
console.error("[UserDocumentRepository] Failed to check user document:", error);
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Get Firestore instance
|
|
81
|
-
* Exported for testing and external use
|
|
82
|
-
*/
|
|
83
|
-
export function getFirestoreInstance(): Firestore {
|
|
84
|
-
return getFirestore();
|
|
85
|
-
}
|