@umituz/react-native-firebase 1.13.40 → 1.13.41
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 +1 -5
- package/src/auth/infrastructure/config/initializers/FirebaseAuthInitializer.ts +8 -38
- package/src/auth/infrastructure/services/anonymous-auth.service.ts +6 -29
- package/src/auth/infrastructure/services/apple-auth.service.ts +3 -32
- package/src/auth/infrastructure/services/google-auth.service.ts +3 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-firebase",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.41",
|
|
4
4
|
"description": "Unified Firebase package for React Native apps - Auth and Firestore services using Firebase JS SDK (no native modules).",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -32,7 +32,6 @@
|
|
|
32
32
|
"url": "https://github.com/umituz/react-native-firebase"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@umituz/react-native-sentry": "*",
|
|
36
35
|
"@umituz/react-native-storage": "*",
|
|
37
36
|
"expo-apple-authentication": ">=6.0.0",
|
|
38
37
|
"expo-crypto": ">=13.0.0",
|
|
@@ -42,11 +41,8 @@
|
|
|
42
41
|
},
|
|
43
42
|
"devDependencies": {
|
|
44
43
|
"@react-native-async-storage/async-storage": "^2.2.0",
|
|
45
|
-
"@sentry/react-native": "^7.8.0",
|
|
46
|
-
"@sentry/types": "^10.32.1",
|
|
47
44
|
"@types/jest": "^30.0.0",
|
|
48
45
|
"@types/react": "~19.1.10",
|
|
49
|
-
"@umituz/react-native-sentry": "*",
|
|
50
46
|
"@umituz/react-native-storage": "*",
|
|
51
47
|
"expo-apple-authentication": "^8.0.8",
|
|
52
48
|
"expo-crypto": "^15.0.8",
|
|
@@ -16,10 +16,6 @@ import type { Auth } from 'firebase/auth';
|
|
|
16
16
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
17
17
|
import type { FirebaseApp } from 'firebase/app';
|
|
18
18
|
import type { FirebaseAuthConfig } from '../../../domain/value-objects/FirebaseAuthConfig';
|
|
19
|
-
import {
|
|
20
|
-
trackPackageError,
|
|
21
|
-
addPackageBreadcrumb,
|
|
22
|
-
trackPackageWarning,
|
|
23
19
|
|
|
24
20
|
declare const __DEV__: boolean;
|
|
25
21
|
|
|
@@ -32,13 +28,13 @@ export class FirebaseAuthInitializer {
|
|
|
32
28
|
* Initialize Firebase Auth with persistence support
|
|
33
29
|
*/
|
|
34
30
|
static initialize(app: FirebaseApp, config?: FirebaseAuthConfig): Auth | null {
|
|
35
|
-
|
|
31
|
+
if (__DEV__) console.log('[Firebase Auth] Initializing...');
|
|
36
32
|
|
|
37
33
|
try {
|
|
38
34
|
const auth = this.initializeWithPersistence(app, config);
|
|
39
35
|
|
|
40
|
-
if (auth) {
|
|
41
|
-
|
|
36
|
+
if (auth && __DEV__) {
|
|
37
|
+
console.log('[Firebase Auth] Successfully initialized');
|
|
42
38
|
}
|
|
43
39
|
|
|
44
40
|
return auth;
|
|
@@ -48,26 +44,15 @@ export class FirebaseAuthInitializer {
|
|
|
48
44
|
}
|
|
49
45
|
|
|
50
46
|
private static handleInitializationError(error: unknown, app: FirebaseApp): Auth | null {
|
|
51
|
-
const errorObj = error instanceof Error ? error : new Error(String(error));
|
|
52
47
|
const errorCode = (error as { code?: string })?.code;
|
|
53
48
|
|
|
54
49
|
if (errorCode === 'auth/already-initialized') {
|
|
55
|
-
|
|
56
|
-
'firebase-auth',
|
|
57
|
-
'Auth already initialized, returning existing instance',
|
|
58
|
-
{ errorCode }
|
|
59
|
-
);
|
|
50
|
+
if (__DEV__) console.log('[Firebase Auth] Already initialized, returning existing instance');
|
|
60
51
|
return this.getExistingAuth(app);
|
|
61
52
|
}
|
|
62
53
|
|
|
63
|
-
trackPackageError(errorObj, {
|
|
64
|
-
packageName: 'firebase-auth',
|
|
65
|
-
operation: 'initialize',
|
|
66
|
-
errorCode,
|
|
67
|
-
});
|
|
68
|
-
|
|
69
54
|
if (__DEV__) {
|
|
70
|
-
console.warn('Firebase Auth
|
|
55
|
+
console.warn('[Firebase Auth] Initialization error:', error);
|
|
71
56
|
}
|
|
72
57
|
|
|
73
58
|
return this.getExistingAuth(app);
|
|
@@ -77,17 +62,8 @@ export class FirebaseAuthInitializer {
|
|
|
77
62
|
try {
|
|
78
63
|
return getAuth(app);
|
|
79
64
|
} catch (getAuthError) {
|
|
80
|
-
const errorObj = getAuthError instanceof Error
|
|
81
|
-
? getAuthError
|
|
82
|
-
: new Error(String(getAuthError));
|
|
83
|
-
|
|
84
|
-
trackPackageError(errorObj, {
|
|
85
|
-
packageName: 'firebase-auth',
|
|
86
|
-
operation: 'getAuth-fallback',
|
|
87
|
-
});
|
|
88
|
-
|
|
89
65
|
if (__DEV__) {
|
|
90
|
-
console.warn('Firebase Auth
|
|
66
|
+
console.warn('[Firebase Auth] Failed to get auth instance:', getAuthError);
|
|
91
67
|
}
|
|
92
68
|
return null;
|
|
93
69
|
}
|
|
@@ -104,20 +80,14 @@ export class FirebaseAuthInitializer {
|
|
|
104
80
|
removeItem: (key: string) => AsyncStorage.removeItem(key),
|
|
105
81
|
};
|
|
106
82
|
|
|
107
|
-
|
|
83
|
+
if (__DEV__) console.log('[Firebase Auth] Initializing with AsyncStorage persistence');
|
|
108
84
|
|
|
109
85
|
return initializeAuth(app, {
|
|
110
86
|
persistence: getReactNativePersistence(storage),
|
|
111
87
|
});
|
|
112
88
|
} catch (error) {
|
|
113
|
-
const errorObj = error instanceof Error ? error : new Error(String(error));
|
|
114
|
-
trackPackageError(errorObj, {
|
|
115
|
-
packageName: 'firebase-auth',
|
|
116
|
-
operation: 'initializeWithPersistence',
|
|
117
|
-
});
|
|
118
|
-
|
|
119
89
|
if (__DEV__) {
|
|
120
|
-
console.warn('Firebase Auth
|
|
90
|
+
console.warn('[Firebase Auth] Persistence initialization failed:', error);
|
|
121
91
|
}
|
|
122
92
|
|
|
123
93
|
return this.getExistingAuth(app);
|
|
@@ -6,9 +6,6 @@
|
|
|
6
6
|
import { signInAnonymously, type Auth, type User } from "firebase/auth";
|
|
7
7
|
import { toAnonymousUser, type AnonymousUser } from "../../domain/entities/AnonymousUser";
|
|
8
8
|
import { checkAuthState } from "./auth-utils.service";
|
|
9
|
-
import {
|
|
10
|
-
trackPackageError,
|
|
11
|
-
addPackageBreadcrumb,
|
|
12
9
|
|
|
13
10
|
declare const __DEV__: boolean;
|
|
14
11
|
|
|
@@ -42,8 +39,7 @@ export class AnonymousAuthService implements AnonymousAuthServiceInterface {
|
|
|
42
39
|
|
|
43
40
|
// If user is already signed in with email/password, preserve that session
|
|
44
41
|
if (currentUser && !currentUser.isAnonymous) {
|
|
45
|
-
if (
|
|
46
|
-
// eslint-disable-next-line no-console
|
|
42
|
+
if (__DEV__) {
|
|
47
43
|
console.log("[AnonymousAuthService] User already signed in with email/password, skipping anonymous auth");
|
|
48
44
|
}
|
|
49
45
|
// Return a "fake" anonymous result to maintain API compatibility
|
|
@@ -57,8 +53,7 @@ export class AnonymousAuthService implements AnonymousAuthServiceInterface {
|
|
|
57
53
|
|
|
58
54
|
// If already signed in anonymously, return existing user
|
|
59
55
|
if (currentUser && currentUser.isAnonymous) {
|
|
60
|
-
if (
|
|
61
|
-
// eslint-disable-next-line no-console
|
|
56
|
+
if (__DEV__) {
|
|
62
57
|
console.log("[AnonymousAuthService] User already signed in anonymously");
|
|
63
58
|
}
|
|
64
59
|
return {
|
|
@@ -69,40 +64,24 @@ export class AnonymousAuthService implements AnonymousAuthServiceInterface {
|
|
|
69
64
|
}
|
|
70
65
|
|
|
71
66
|
// No user exists, sign in anonymously
|
|
72
|
-
addPackageBreadcrumb("firebase-auth", "Starting anonymous sign-in");
|
|
73
|
-
|
|
74
67
|
try {
|
|
75
68
|
const userCredential = await signInAnonymously(auth);
|
|
76
69
|
const anonymousUser = toAnonymousUser(userCredential.user);
|
|
77
70
|
|
|
78
|
-
if (
|
|
79
|
-
// eslint-disable-next-line no-console
|
|
71
|
+
if (__DEV__) {
|
|
80
72
|
console.log("[AnonymousAuthService] Successfully signed in anonymously", { uid: anonymousUser.uid });
|
|
81
73
|
}
|
|
82
74
|
|
|
83
|
-
addPackageBreadcrumb("firebase-auth", "Anonymous sign-in successful", {
|
|
84
|
-
userId: anonymousUser.uid,
|
|
85
|
-
});
|
|
86
|
-
|
|
87
75
|
return {
|
|
88
76
|
user: userCredential.user,
|
|
89
77
|
anonymousUser,
|
|
90
78
|
wasAlreadySignedIn: false,
|
|
91
79
|
};
|
|
92
80
|
} catch (error) {
|
|
93
|
-
if (
|
|
94
|
-
// eslint-disable-next-line no-console
|
|
81
|
+
if (__DEV__) {
|
|
95
82
|
console.error("[AnonymousAuthService] Failed to sign in anonymously", error);
|
|
96
83
|
}
|
|
97
84
|
|
|
98
|
-
trackPackageError(
|
|
99
|
-
error instanceof Error ? error : new Error("Anonymous sign-in failed"),
|
|
100
|
-
{
|
|
101
|
-
packageName: "firebase-auth",
|
|
102
|
-
operation: "anonymous-sign-in",
|
|
103
|
-
}
|
|
104
|
-
);
|
|
105
|
-
|
|
106
85
|
throw error;
|
|
107
86
|
}
|
|
108
87
|
}
|
|
@@ -122,8 +101,7 @@ export class AnonymousAuthService implements AnonymousAuthServiceInterface {
|
|
|
122
101
|
}
|
|
123
102
|
return null;
|
|
124
103
|
} catch (error) {
|
|
125
|
-
if (
|
|
126
|
-
// eslint-disable-next-line no-console
|
|
104
|
+
if (__DEV__) {
|
|
127
105
|
console.error("[AnonymousAuthService] Error getting current anonymous user", error);
|
|
128
106
|
}
|
|
129
107
|
return null;
|
|
@@ -141,8 +119,7 @@ export class AnonymousAuthService implements AnonymousAuthServiceInterface {
|
|
|
141
119
|
try {
|
|
142
120
|
return checkAuthState(auth).isAnonymous;
|
|
143
121
|
} catch (error) {
|
|
144
|
-
if (
|
|
145
|
-
// eslint-disable-next-line no-console
|
|
122
|
+
if (__DEV__) {
|
|
146
123
|
console.error("[AnonymousAuthService] Error checking if user is anonymous", error);
|
|
147
124
|
}
|
|
148
125
|
return false;
|
|
@@ -13,9 +13,6 @@ import {
|
|
|
13
13
|
import * as AppleAuthentication from "expo-apple-authentication";
|
|
14
14
|
import * as Crypto from "expo-crypto";
|
|
15
15
|
import { Platform } from "react-native";
|
|
16
|
-
import {
|
|
17
|
-
trackPackageError,
|
|
18
|
-
addPackageBreadcrumb,
|
|
19
16
|
|
|
20
17
|
/**
|
|
21
18
|
* Apple Auth result
|
|
@@ -53,15 +50,10 @@ export class AppleAuthService {
|
|
|
53
50
|
* Handles the complete Apple Sign-In flow
|
|
54
51
|
*/
|
|
55
52
|
async signIn(auth: Auth): Promise<AppleAuthResult> {
|
|
56
|
-
addPackageBreadcrumb("firebase-auth", "Apple Sign-In started");
|
|
57
|
-
|
|
58
53
|
try {
|
|
59
54
|
// Check availability
|
|
60
55
|
const isAvailable = await this.isAvailable();
|
|
61
56
|
if (!isAvailable) {
|
|
62
|
-
addPackageBreadcrumb("firebase-auth", "Apple Sign-In not available", {
|
|
63
|
-
platform: Platform.OS,
|
|
64
|
-
});
|
|
65
57
|
return {
|
|
66
58
|
success: false,
|
|
67
59
|
error: "Apple Sign-In is not available on this device",
|
|
@@ -75,8 +67,6 @@ export class AppleAuthService {
|
|
|
75
67
|
nonce,
|
|
76
68
|
);
|
|
77
69
|
|
|
78
|
-
addPackageBreadcrumb("firebase-auth", "Requesting Apple credentials");
|
|
79
|
-
|
|
80
70
|
// Request Apple Sign-In
|
|
81
71
|
const appleCredential = await AppleAuthentication.signInAsync({
|
|
82
72
|
requestedScopes: [
|
|
@@ -88,19 +78,12 @@ export class AppleAuthService {
|
|
|
88
78
|
|
|
89
79
|
// Check for identity token
|
|
90
80
|
if (!appleCredential.identityToken) {
|
|
91
|
-
const error = new Error("No identity token received from Apple");
|
|
92
|
-
trackPackageError(error, {
|
|
93
|
-
packageName: "firebase-auth",
|
|
94
|
-
operation: "apple-sign-in",
|
|
95
|
-
});
|
|
96
81
|
return {
|
|
97
82
|
success: false,
|
|
98
83
|
error: "No identity token received from Apple",
|
|
99
84
|
};
|
|
100
85
|
}
|
|
101
86
|
|
|
102
|
-
addPackageBreadcrumb("firebase-auth", "Creating Firebase credential");
|
|
103
|
-
|
|
104
87
|
// Create Firebase credential
|
|
105
88
|
const provider = new OAuthProvider("apple.com");
|
|
106
89
|
const credential = provider.credential({
|
|
@@ -116,11 +99,6 @@ export class AppleAuthService {
|
|
|
116
99
|
userCredential.user.metadata.creationTime ===
|
|
117
100
|
userCredential.user.metadata.lastSignInTime;
|
|
118
101
|
|
|
119
|
-
addPackageBreadcrumb("firebase-auth", "Apple Sign-In successful", {
|
|
120
|
-
isNewUser,
|
|
121
|
-
userId: userCredential.user.uid,
|
|
122
|
-
});
|
|
123
|
-
|
|
124
102
|
return {
|
|
125
103
|
success: true,
|
|
126
104
|
userCredential,
|
|
@@ -132,22 +110,15 @@ export class AppleAuthService {
|
|
|
132
110
|
error instanceof Error &&
|
|
133
111
|
error.message.includes("ERR_CANCELED")
|
|
134
112
|
) {
|
|
135
|
-
addPackageBreadcrumb("firebase-auth", "Apple Sign-In cancelled by user");
|
|
136
113
|
return {
|
|
137
114
|
success: false,
|
|
138
115
|
error: "Apple Sign-In was cancelled",
|
|
139
116
|
};
|
|
140
117
|
}
|
|
141
118
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
{
|
|
146
|
-
packageName: "firebase-auth",
|
|
147
|
-
operation: "apple-sign-in",
|
|
148
|
-
platform: Platform.OS,
|
|
149
|
-
}
|
|
150
|
-
);
|
|
119
|
+
if (__DEV__) {
|
|
120
|
+
console.error('[Firebase Auth] Apple Sign-In failed:', error);
|
|
121
|
+
}
|
|
151
122
|
|
|
152
123
|
return {
|
|
153
124
|
success: false,
|
|
@@ -10,9 +10,6 @@ import {
|
|
|
10
10
|
type Auth,
|
|
11
11
|
type UserCredential,
|
|
12
12
|
} from "firebase/auth";
|
|
13
|
-
import {
|
|
14
|
-
trackPackageError,
|
|
15
|
-
addPackageBreadcrumb,
|
|
16
13
|
|
|
17
14
|
/**
|
|
18
15
|
* Google Auth configuration
|
|
@@ -74,8 +71,6 @@ export class GoogleAuthService {
|
|
|
74
71
|
auth: Auth,
|
|
75
72
|
idToken: string,
|
|
76
73
|
): Promise<GoogleAuthResult> {
|
|
77
|
-
addPackageBreadcrumb("firebase-auth", "Google Sign-In with ID token");
|
|
78
|
-
|
|
79
74
|
try {
|
|
80
75
|
const credential = GoogleAuthProvider.credential(idToken);
|
|
81
76
|
const userCredential = await signInWithCredential(auth, credential);
|
|
@@ -85,24 +80,15 @@ export class GoogleAuthService {
|
|
|
85
80
|
userCredential.user.metadata.creationTime ===
|
|
86
81
|
userCredential.user.metadata.lastSignInTime;
|
|
87
82
|
|
|
88
|
-
addPackageBreadcrumb("firebase-auth", "Google Sign-In successful", {
|
|
89
|
-
isNewUser,
|
|
90
|
-
userId: userCredential.user.uid,
|
|
91
|
-
});
|
|
92
|
-
|
|
93
83
|
return {
|
|
94
84
|
success: true,
|
|
95
85
|
userCredential,
|
|
96
86
|
isNewUser,
|
|
97
87
|
};
|
|
98
88
|
} catch (error) {
|
|
99
|
-
|
|
100
|
-
error
|
|
101
|
-
|
|
102
|
-
packageName: "firebase-auth",
|
|
103
|
-
operation: "google-sign-in",
|
|
104
|
-
}
|
|
105
|
-
);
|
|
89
|
+
if (__DEV__) {
|
|
90
|
+
console.error('[Firebase Auth] Google Sign-In failed:', error);
|
|
91
|
+
}
|
|
106
92
|
|
|
107
93
|
return {
|
|
108
94
|
success: false,
|