@umituz/react-native-firebase 1.13.41 → 1.13.43
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-firebase",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.43",
|
|
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",
|
|
@@ -7,8 +7,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
9
|
|
|
10
|
-
declare const __DEV__: boolean;
|
|
11
|
-
|
|
12
10
|
export interface AnonymousAuthResult {
|
|
13
11
|
readonly user: User;
|
|
14
12
|
readonly anonymousUser: AnonymousUser;
|
|
@@ -17,33 +15,15 @@ export interface AnonymousAuthResult {
|
|
|
17
15
|
|
|
18
16
|
export interface AnonymousAuthServiceInterface {
|
|
19
17
|
signInAnonymously(auth: Auth): Promise<AnonymousAuthResult>;
|
|
20
|
-
getCurrentAnonymousUser(auth: Auth | null): User | null;
|
|
21
|
-
isCurrentUserAnonymous(auth: Auth | null): boolean;
|
|
22
18
|
}
|
|
23
19
|
|
|
24
|
-
/**
|
|
25
|
-
* Anonymous Auth Service
|
|
26
|
-
* Handles anonymous authentication operations
|
|
27
|
-
*/
|
|
28
20
|
export class AnonymousAuthService implements AnonymousAuthServiceInterface {
|
|
29
|
-
/**
|
|
30
|
-
* Sign in anonymously
|
|
31
|
-
* IMPORTANT: Only signs in if NO user exists (preserves email/password sessions)
|
|
32
|
-
*/
|
|
33
21
|
async signInAnonymously(auth: Auth): Promise<AnonymousAuthResult> {
|
|
34
|
-
if (!auth)
|
|
35
|
-
throw new Error("Firebase Auth instance is required");
|
|
36
|
-
}
|
|
22
|
+
if (!auth) throw new Error("Firebase Auth instance is required");
|
|
37
23
|
|
|
38
24
|
const currentUser = auth.currentUser;
|
|
39
25
|
|
|
40
|
-
// If user is already signed in with email/password, preserve that session
|
|
41
26
|
if (currentUser && !currentUser.isAnonymous) {
|
|
42
|
-
if (__DEV__) {
|
|
43
|
-
console.log("[AnonymousAuthService] User already signed in with email/password, skipping anonymous auth");
|
|
44
|
-
}
|
|
45
|
-
// Return a "fake" anonymous result to maintain API compatibility
|
|
46
|
-
// The actual user is NOT anonymous
|
|
47
27
|
return {
|
|
48
28
|
user: currentUser,
|
|
49
29
|
anonymousUser: toAnonymousUser(currentUser),
|
|
@@ -51,11 +31,7 @@ export class AnonymousAuthService implements AnonymousAuthServiceInterface {
|
|
|
51
31
|
};
|
|
52
32
|
}
|
|
53
33
|
|
|
54
|
-
// If already signed in anonymously, return existing user
|
|
55
34
|
if (currentUser && currentUser.isAnonymous) {
|
|
56
|
-
if (__DEV__) {
|
|
57
|
-
console.log("[AnonymousAuthService] User already signed in anonymously");
|
|
58
|
-
}
|
|
59
35
|
return {
|
|
60
36
|
user: currentUser,
|
|
61
37
|
anonymousUser: toAnonymousUser(currentUser),
|
|
@@ -63,68 +39,19 @@ export class AnonymousAuthService implements AnonymousAuthServiceInterface {
|
|
|
63
39
|
};
|
|
64
40
|
}
|
|
65
41
|
|
|
66
|
-
// No user exists, sign in anonymously
|
|
67
42
|
try {
|
|
68
43
|
const userCredential = await signInAnonymously(auth);
|
|
69
44
|
const anonymousUser = toAnonymousUser(userCredential.user);
|
|
70
|
-
|
|
71
|
-
if (__DEV__) {
|
|
72
|
-
console.log("[AnonymousAuthService] Successfully signed in anonymously", { uid: anonymousUser.uid });
|
|
73
|
-
}
|
|
74
|
-
|
|
75
45
|
return {
|
|
76
46
|
user: userCredential.user,
|
|
77
47
|
anonymousUser,
|
|
78
48
|
wasAlreadySignedIn: false,
|
|
79
49
|
};
|
|
80
50
|
} catch (error) {
|
|
81
|
-
if (__DEV__)
|
|
82
|
-
console.error("[AnonymousAuthService] Failed to sign in anonymously", error);
|
|
83
|
-
}
|
|
84
|
-
|
|
51
|
+
if (__DEV__) console.error("[AnonymousAuthService] Failed", error);
|
|
85
52
|
throw error;
|
|
86
53
|
}
|
|
87
54
|
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Get current anonymous user
|
|
91
|
-
*/
|
|
92
|
-
getCurrentAnonymousUser(auth: Auth | null): User | null {
|
|
93
|
-
if (!auth) {
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
try {
|
|
98
|
-
const state = checkAuthState(auth);
|
|
99
|
-
if (state.isAnonymous && state.currentUser) {
|
|
100
|
-
return state.currentUser;
|
|
101
|
-
}
|
|
102
|
-
return null;
|
|
103
|
-
} catch (error) {
|
|
104
|
-
if (__DEV__) {
|
|
105
|
-
console.error("[AnonymousAuthService] Error getting current anonymous user", error);
|
|
106
|
-
}
|
|
107
|
-
return null;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Check if current user is anonymous
|
|
113
|
-
*/
|
|
114
|
-
isCurrentUserAnonymous(auth: Auth | null): boolean {
|
|
115
|
-
if (!auth) {
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
try {
|
|
120
|
-
return checkAuthState(auth).isAnonymous;
|
|
121
|
-
} catch (error) {
|
|
122
|
-
if (__DEV__) {
|
|
123
|
-
console.error("[AnonymousAuthService] Error checking if user is anonymous", error);
|
|
124
|
-
}
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
55
|
}
|
|
129
56
|
|
|
130
57
|
export const anonymousAuthService = new AnonymousAuthService();
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Apple Auth Service
|
|
3
3
|
* Handles Apple Sign-In with Firebase Authentication
|
|
4
|
-
* Uses expo-apple-authentication for native Apple Sign-In
|
|
5
4
|
*/
|
|
6
5
|
|
|
7
6
|
import {
|
|
@@ -14,9 +13,6 @@ import * as AppleAuthentication from "expo-apple-authentication";
|
|
|
14
13
|
import * as Crypto from "expo-crypto";
|
|
15
14
|
import { Platform } from "react-native";
|
|
16
15
|
|
|
17
|
-
/**
|
|
18
|
-
* Apple Auth result
|
|
19
|
-
*/
|
|
20
16
|
export interface AppleAuthResult {
|
|
21
17
|
success: boolean;
|
|
22
18
|
userCredential?: UserCredential;
|
|
@@ -24,20 +20,9 @@ export interface AppleAuthResult {
|
|
|
24
20
|
isNewUser?: boolean;
|
|
25
21
|
}
|
|
26
22
|
|
|
27
|
-
/**
|
|
28
|
-
* Apple Auth Service
|
|
29
|
-
* Provides Apple Sign-In functionality for Firebase (iOS only)
|
|
30
|
-
*/
|
|
31
23
|
export class AppleAuthService {
|
|
32
|
-
/**
|
|
33
|
-
* Check if Apple Sign-In is available
|
|
34
|
-
* Only available on iOS 13+
|
|
35
|
-
*/
|
|
36
24
|
async isAvailable(): Promise<boolean> {
|
|
37
|
-
if (Platform.OS !== "ios")
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
|
|
25
|
+
if (Platform.OS !== "ios") return false;
|
|
41
26
|
try {
|
|
42
27
|
return await AppleAuthentication.isAvailableAsync();
|
|
43
28
|
} catch {
|
|
@@ -45,13 +30,8 @@ export class AppleAuthService {
|
|
|
45
30
|
}
|
|
46
31
|
}
|
|
47
32
|
|
|
48
|
-
/**
|
|
49
|
-
* Sign in with Apple
|
|
50
|
-
* Handles the complete Apple Sign-In flow
|
|
51
|
-
*/
|
|
52
33
|
async signIn(auth: Auth): Promise<AppleAuthResult> {
|
|
53
34
|
try {
|
|
54
|
-
// Check availability
|
|
55
35
|
const isAvailable = await this.isAvailable();
|
|
56
36
|
if (!isAvailable) {
|
|
57
37
|
return {
|
|
@@ -60,14 +40,12 @@ export class AppleAuthService {
|
|
|
60
40
|
};
|
|
61
41
|
}
|
|
62
42
|
|
|
63
|
-
// Generate nonce for security
|
|
64
43
|
const nonce = await this.generateNonce();
|
|
65
44
|
const hashedNonce = await Crypto.digestStringAsync(
|
|
66
45
|
Crypto.CryptoDigestAlgorithm.SHA256,
|
|
67
46
|
nonce,
|
|
68
47
|
);
|
|
69
48
|
|
|
70
|
-
// Request Apple Sign-In
|
|
71
49
|
const appleCredential = await AppleAuthentication.signInAsync({
|
|
72
50
|
requestedScopes: [
|
|
73
51
|
AppleAuthentication.AppleAuthenticationScope.FULL_NAME,
|
|
@@ -76,25 +54,17 @@ export class AppleAuthService {
|
|
|
76
54
|
nonce: hashedNonce,
|
|
77
55
|
});
|
|
78
56
|
|
|
79
|
-
// Check for identity token
|
|
80
57
|
if (!appleCredential.identityToken) {
|
|
81
|
-
return {
|
|
82
|
-
success: false,
|
|
83
|
-
error: "No identity token received from Apple",
|
|
84
|
-
};
|
|
58
|
+
return { success: false, error: "No identity token received" };
|
|
85
59
|
}
|
|
86
60
|
|
|
87
|
-
// Create Firebase credential
|
|
88
61
|
const provider = new OAuthProvider("apple.com");
|
|
89
62
|
const credential = provider.credential({
|
|
90
63
|
idToken: appleCredential.identityToken,
|
|
91
64
|
rawNonce: nonce,
|
|
92
65
|
});
|
|
93
66
|
|
|
94
|
-
// Sign in to Firebase
|
|
95
67
|
const userCredential = await signInWithCredential(auth, credential);
|
|
96
|
-
|
|
97
|
-
// Check if this is a new user
|
|
98
68
|
const isNewUser =
|
|
99
69
|
userCredential.user.metadata.creationTime ===
|
|
100
70
|
userCredential.user.metadata.lastSignInTime;
|
|
@@ -105,21 +75,10 @@ export class AppleAuthService {
|
|
|
105
75
|
isNewUser,
|
|
106
76
|
};
|
|
107
77
|
} catch (error) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
error instanceof Error &&
|
|
111
|
-
error.message.includes("ERR_CANCELED")
|
|
112
|
-
) {
|
|
113
|
-
return {
|
|
114
|
-
success: false,
|
|
115
|
-
error: "Apple Sign-In was cancelled",
|
|
116
|
-
};
|
|
78
|
+
if (error instanceof Error && error.message.includes("ERR_CANCELED")) {
|
|
79
|
+
return { success: false, error: "Apple Sign-In was cancelled" };
|
|
117
80
|
}
|
|
118
|
-
|
|
119
|
-
if (__DEV__) {
|
|
120
|
-
console.error('[Firebase Auth] Apple Sign-In failed:', error);
|
|
121
|
-
}
|
|
122
|
-
|
|
81
|
+
if (__DEV__) console.error('[Firebase Auth] Apple Sign-In failed:', error);
|
|
123
82
|
return {
|
|
124
83
|
success: false,
|
|
125
84
|
error: error instanceof Error ? error.message : "Apple sign-in failed",
|
|
@@ -127,27 +86,16 @@ export class AppleAuthService {
|
|
|
127
86
|
}
|
|
128
87
|
}
|
|
129
88
|
|
|
130
|
-
/**
|
|
131
|
-
* Generate a random nonce for Apple Sign-In security
|
|
132
|
-
*/
|
|
133
89
|
private async generateNonce(length: number = 32): Promise<string> {
|
|
134
90
|
const randomBytes = await Crypto.getRandomBytesAsync(length);
|
|
135
|
-
const chars =
|
|
136
|
-
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
91
|
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
137
92
|
let result = "";
|
|
138
|
-
|
|
139
93
|
for (let i = 0; i < randomBytes.length; i++) {
|
|
140
94
|
const byte = randomBytes[i];
|
|
141
|
-
if (byte !== undefined)
|
|
142
|
-
result += chars.charAt(byte % chars.length);
|
|
143
|
-
}
|
|
95
|
+
if (byte !== undefined) result += chars.charAt(byte % chars.length);
|
|
144
96
|
}
|
|
145
|
-
|
|
146
97
|
return result;
|
|
147
98
|
}
|
|
148
99
|
}
|
|
149
100
|
|
|
150
|
-
/**
|
|
151
|
-
* Singleton instance
|
|
152
|
-
*/
|
|
153
101
|
export const appleAuthService = new AppleAuthService();
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Google Auth Service
|
|
3
3
|
* Handles Google Sign-In with Firebase Authentication
|
|
4
|
-
* Uses expo-auth-session for OAuth flow
|
|
5
4
|
*/
|
|
6
5
|
|
|
7
6
|
import {
|
|
@@ -37,16 +36,10 @@ export interface GoogleAuthResult {
|
|
|
37
36
|
export class GoogleAuthService {
|
|
38
37
|
private config: GoogleAuthConfig | null = null;
|
|
39
38
|
|
|
40
|
-
/**
|
|
41
|
-
* Configure Google Auth with client IDs
|
|
42
|
-
*/
|
|
43
39
|
configure(config: GoogleAuthConfig): void {
|
|
44
40
|
this.config = config;
|
|
45
41
|
}
|
|
46
42
|
|
|
47
|
-
/**
|
|
48
|
-
* Check if Google Auth is configured
|
|
49
|
-
*/
|
|
50
43
|
isConfigured(): boolean {
|
|
51
44
|
return (
|
|
52
45
|
this.config !== null &&
|
|
@@ -56,17 +49,10 @@ export class GoogleAuthService {
|
|
|
56
49
|
);
|
|
57
50
|
}
|
|
58
51
|
|
|
59
|
-
/**
|
|
60
|
-
* Get the current configuration
|
|
61
|
-
*/
|
|
62
52
|
getConfig(): GoogleAuthConfig | null {
|
|
63
53
|
return this.config;
|
|
64
54
|
}
|
|
65
55
|
|
|
66
|
-
/**
|
|
67
|
-
* Sign in with Google ID token
|
|
68
|
-
* Called after successful Google OAuth flow
|
|
69
|
-
*/
|
|
70
56
|
async signInWithIdToken(
|
|
71
57
|
auth: Auth,
|
|
72
58
|
idToken: string,
|
|
@@ -75,7 +61,6 @@ export class GoogleAuthService {
|
|
|
75
61
|
const credential = GoogleAuthProvider.credential(idToken);
|
|
76
62
|
const userCredential = await signInWithCredential(auth, credential);
|
|
77
63
|
|
|
78
|
-
// Check if this is a new user
|
|
79
64
|
const isNewUser =
|
|
80
65
|
userCredential.user.metadata.creationTime ===
|
|
81
66
|
userCredential.user.metadata.lastSignInTime;
|
|
@@ -89,7 +74,6 @@ export class GoogleAuthService {
|
|
|
89
74
|
if (__DEV__) {
|
|
90
75
|
console.error('[Firebase Auth] Google Sign-In failed:', error);
|
|
91
76
|
}
|
|
92
|
-
|
|
93
77
|
return {
|
|
94
78
|
success: false,
|
|
95
79
|
error: error instanceof Error ? error.message : "Google sign-in failed",
|
|
@@ -98,7 +82,4 @@ export class GoogleAuthService {
|
|
|
98
82
|
}
|
|
99
83
|
}
|
|
100
84
|
|
|
101
|
-
/**
|
|
102
|
-
* Singleton instance
|
|
103
|
-
*/
|
|
104
85
|
export const googleAuthService = new GoogleAuthService();
|