@umituz/react-native-firebase 2.4.34 → 2.4.35
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 -1
- package/src/domains/auth/infrastructure/services/apple-auth.service.ts +2 -1
- package/src/domains/auth/infrastructure/services/google-auth.service.ts +2 -1
- package/src/domains/auth/infrastructure/services/google-oauth.service.ts +1 -1
- package/src/domains/auth/infrastructure/services/user-document-builder.util.ts +1 -2
- package/src/domains/auth/infrastructure/services/utils/auth-result-converter.util.ts +5 -4
- package/src/domains/auth/presentation/hooks/useAnonymousAuth.ts +4 -6
- package/src/domains/auth/presentation/hooks/utils/auth-state-change.handler.ts +0 -5
- package/src/shared/domain/guards/firebase-error.guard.ts +4 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-firebase",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.35",
|
|
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",
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
OAuthProvider,
|
|
9
9
|
signInWithCredential,
|
|
10
10
|
type Auth,
|
|
11
|
+
type UserCredential,
|
|
11
12
|
} from "firebase/auth";
|
|
12
13
|
import { Platform } from "react-native";
|
|
13
14
|
import { generateNonce, hashNonce } from "./crypto.util";
|
|
@@ -43,7 +44,7 @@ export class AppleAuthService {
|
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
private convertToAppleAuthResult(result: Result<{ userCredential:
|
|
47
|
+
private convertToAppleAuthResult(result: Result<{ userCredential: UserCredential; isNewUser: boolean }>): AppleAuthResult {
|
|
47
48
|
return convertToOAuthResult(result, "Apple sign-in failed");
|
|
48
49
|
}
|
|
49
50
|
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
GoogleAuthProvider,
|
|
8
8
|
signInWithCredential,
|
|
9
9
|
type Auth,
|
|
10
|
+
type UserCredential,
|
|
10
11
|
} from "firebase/auth";
|
|
11
12
|
import type { GoogleAuthConfig, GoogleAuthResult } from "./google-auth.types";
|
|
12
13
|
import { executeAuthOperation, type Result } from "../../../../shared/domain/utils";
|
|
@@ -26,7 +27,7 @@ export class GoogleAuthService extends ConfigurableService<GoogleAuthConfig> {
|
|
|
26
27
|
);
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
private convertToGoogleAuthResult(result: Result<{ userCredential:
|
|
30
|
+
private convertToGoogleAuthResult(result: Result<{ userCredential: UserCredential; isNewUser: boolean }>): GoogleAuthResult {
|
|
30
31
|
return convertToOAuthResult(result, "Google sign-in failed");
|
|
31
32
|
}
|
|
32
33
|
|
|
@@ -68,7 +68,7 @@ export class GoogleOAuthService {
|
|
|
68
68
|
async signInWithOAuth(
|
|
69
69
|
auth: Auth,
|
|
70
70
|
config?: GoogleOAuthConfig,
|
|
71
|
-
promptAsync?: () => Promise<
|
|
71
|
+
promptAsync?: () => Promise<{ type: string; authentication?: { idToken?: string } | null }>
|
|
72
72
|
): Promise<GoogleAuthResult> {
|
|
73
73
|
if (!isExpoAuthAvailable) {
|
|
74
74
|
return {
|
|
@@ -17,7 +17,7 @@ function hasProviderData(user: unknown): user is { providerData: { providerId: s
|
|
|
17
17
|
typeof user === 'object' &&
|
|
18
18
|
user !== null &&
|
|
19
19
|
'providerData' in user &&
|
|
20
|
-
Array.isArray((user as
|
|
20
|
+
Array.isArray((user as Record<string, unknown>).providerData)
|
|
21
21
|
);
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -27,7 +27,6 @@ function hasProviderData(user: unknown): user is { providerData: { providerId: s
|
|
|
27
27
|
export function getSignUpMethod(user: UserDocumentUser): string | undefined {
|
|
28
28
|
if (user.isAnonymous) return "anonymous";
|
|
29
29
|
if (user.email) {
|
|
30
|
-
// FIX: Use type guard instead of unsafe cast
|
|
31
30
|
if (hasProviderData(user) && user.providerData.length > 0) {
|
|
32
31
|
const providerId = user.providerData[0]?.providerId;
|
|
33
32
|
if (providerId === "google.com") return "google";
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Eliminates duplicate result conversion logic in OAuth providers (Apple, Google)
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import type { UserCredential } from 'firebase/auth';
|
|
7
8
|
import { isSuccess } from '../../../../../shared/domain/utils/result/result-helpers';
|
|
8
9
|
import type { Result } from '../../../../../shared/domain/utils/result/result-types';
|
|
9
10
|
|
|
@@ -13,7 +14,7 @@ import type { Result } from '../../../../../shared/domain/utils/result/result-ty
|
|
|
13
14
|
*/
|
|
14
15
|
interface OAuthAuthSuccessResult {
|
|
15
16
|
success: true;
|
|
16
|
-
userCredential:
|
|
17
|
+
userCredential: UserCredential;
|
|
17
18
|
isNewUser: boolean;
|
|
18
19
|
}
|
|
19
20
|
|
|
@@ -42,18 +43,18 @@ type OAuthAuthResult = OAuthAuthSuccessResult | OAuthAuthErrorResult;
|
|
|
42
43
|
* @example
|
|
43
44
|
* ```typescript
|
|
44
45
|
* // In AppleAuthService
|
|
45
|
-
* private convertToAppleAuthResult(result: Result<{ userCredential:
|
|
46
|
+
* private convertToAppleAuthResult(result: Result<{ userCredential: UserCredential; isNewUser: boolean }>): AppleAuthResult {
|
|
46
47
|
* return convertToOAuthResult(result, "Apple sign-in failed");
|
|
47
48
|
* }
|
|
48
49
|
*
|
|
49
50
|
* // In GoogleAuthService
|
|
50
|
-
* private convertToGoogleAuthResult(result: Result<{ userCredential:
|
|
51
|
+
* private convertToGoogleAuthResult(result: Result<{ userCredential: UserCredential; isNewUser: boolean }>): GoogleAuthResult {
|
|
51
52
|
* return convertToOAuthResult(result, "Google sign-in failed");
|
|
52
53
|
* }
|
|
53
54
|
* ```
|
|
54
55
|
*/
|
|
55
56
|
export function convertToOAuthResult(
|
|
56
|
-
result: Result<{ userCredential:
|
|
57
|
+
result: Result<{ userCredential: UserCredential; isNewUser: boolean }>,
|
|
57
58
|
defaultErrorMessage: string = 'Authentication failed'
|
|
58
59
|
): OAuthAuthResult {
|
|
59
60
|
if (isSuccess(result) && result.data) {
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
import { useState, useEffect, useCallback, useRef } from "react";
|
|
7
7
|
import { onAuthStateChanged, type Auth, type User } from "firebase/auth";
|
|
8
|
-
import type
|
|
8
|
+
import { createAuthCheckResult, type AuthCheckResult } from "../../infrastructure/services/auth-utils.service";
|
|
9
9
|
import { anonymousAuthService, type AnonymousAuthResult } from "../../infrastructure/services/anonymous-auth.service";
|
|
10
|
-
import { createAuthStateChangeHandler
|
|
10
|
+
import { createAuthStateChangeHandler } from "./utils/auth-state-change.handler";
|
|
11
11
|
|
|
12
12
|
export interface UseAnonymousAuthResult extends AuthCheckResult {
|
|
13
13
|
/**
|
|
@@ -69,10 +69,9 @@ export function useAnonymousAuth(auth: Auth | null): UseAnonymousAuthResult {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
if (!auth) {
|
|
72
|
-
setAuthState(
|
|
72
|
+
setAuthState(createAuthCheckResult(null));
|
|
73
73
|
setLoading(false);
|
|
74
74
|
setError(null);
|
|
75
|
-
// FIX: Always return cleanup function to prevent memory leaks
|
|
76
75
|
return () => {
|
|
77
76
|
if (unsubscribeRef.current) {
|
|
78
77
|
unsubscribeRef.current();
|
|
@@ -93,8 +92,7 @@ export function useAnonymousAuth(auth: Auth | null): UseAnonymousAuthResult {
|
|
|
93
92
|
const authError = err instanceof Error ? err : new Error('Auth listener setup failed');
|
|
94
93
|
setError(authError);
|
|
95
94
|
setLoading(false);
|
|
96
|
-
|
|
97
|
-
setAuthState(userToAuthCheckResult(null));
|
|
95
|
+
setAuthState(createAuthCheckResult(null));
|
|
98
96
|
}
|
|
99
97
|
|
|
100
98
|
// Cleanup function
|
|
@@ -27,9 +27,8 @@ export function isFirestoreError(error: unknown): error is FirestoreError {
|
|
|
27
27
|
error !== null &&
|
|
28
28
|
'code' in error &&
|
|
29
29
|
'message' in error &&
|
|
30
|
-
|
|
31
|
-
typeof (error as
|
|
32
|
-
typeof (error as any).message === 'string'
|
|
30
|
+
typeof (error as { code: unknown; message: unknown }).code === 'string' &&
|
|
31
|
+
typeof (error as { code: unknown; message: unknown }).message === 'string'
|
|
33
32
|
);
|
|
34
33
|
}
|
|
35
34
|
|
|
@@ -42,9 +41,8 @@ export function isAuthError(error: unknown): error is AuthError {
|
|
|
42
41
|
error !== null &&
|
|
43
42
|
'code' in error &&
|
|
44
43
|
'message' in error &&
|
|
45
|
-
|
|
46
|
-
typeof (error as
|
|
47
|
-
typeof (error as any).message === 'string'
|
|
44
|
+
typeof (error as { code: unknown; message: unknown }).code === 'string' &&
|
|
45
|
+
typeof (error as { code: unknown; message: unknown }).message === 'string'
|
|
48
46
|
);
|
|
49
47
|
}
|
|
50
48
|
|