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