@umituz/react-native-auth 3.4.6 → 3.4.8
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/domain/utils/migration.ts +2 -2
- package/src/infrastructure/services/UserDocumentService.ts +3 -3
- package/src/infrastructure/services/initializeAuth.ts +34 -32
- package/src/presentation/components/AuthContainer.tsx +19 -10
- package/src/presentation/hooks/useAppleAuth.ts +0 -13
- package/src/presentation/hooks/useGoogleAuth.ts +3 -18
- package/src/presentation/hooks/useSocialLogin.ts +0 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-auth",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.8",
|
|
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",
|
|
@@ -15,10 +15,10 @@ export const configureMigration = (config: MigrationConfig): void => {
|
|
|
15
15
|
migrationConfig = config;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
export const migrateUserData =
|
|
18
|
+
export const migrateUserData = (
|
|
19
19
|
anonymousId: string,
|
|
20
20
|
authId: string
|
|
21
|
-
):
|
|
21
|
+
): void => {
|
|
22
22
|
if (__DEV__) {
|
|
23
23
|
console.log(`[Migration] Starting migration from ${anonymousId} to ${authId}`);
|
|
24
24
|
}
|
|
@@ -187,13 +187,13 @@ export async function ensureUserDocument(
|
|
|
187
187
|
const collectionName = userDocumentConfig.collectionName || "users";
|
|
188
188
|
const userRef = doc(db, collectionName, user.uid);
|
|
189
189
|
const userDoc = await getDoc(userRef);
|
|
190
|
-
const baseData = buildBaseData(user, allExtras
|
|
190
|
+
const baseData = buildBaseData(user, allExtras);
|
|
191
191
|
|
|
192
192
|
if (!userDoc.exists()) {
|
|
193
|
-
const createData = buildCreateData(baseData, allExtras
|
|
193
|
+
const createData = buildCreateData(baseData, allExtras);
|
|
194
194
|
await setDoc(userRef, createData);
|
|
195
195
|
} else {
|
|
196
|
-
const updateData = buildUpdateData(baseData, allExtras
|
|
196
|
+
const updateData = buildUpdateData(baseData, allExtras);
|
|
197
197
|
await setDoc(userRef, updateData, { merge: true });
|
|
198
198
|
}
|
|
199
199
|
|
|
@@ -122,42 +122,44 @@ export async function initializeAuth(
|
|
|
122
122
|
// 4. Initialize Auth Listener (for state management)
|
|
123
123
|
initializeAuthListener({
|
|
124
124
|
autoAnonymousSignIn,
|
|
125
|
-
onAuthStateChange:
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const currentUserId = user.uid;
|
|
135
|
-
const isCurrentlyAnonymous = user.isAnonymous ?? false;
|
|
136
|
-
|
|
137
|
-
// Detect anonymous-to-authenticated conversion
|
|
138
|
-
if (
|
|
139
|
-
previousUserId &&
|
|
140
|
-
previousUserId !== currentUserId &&
|
|
141
|
-
wasAnonymous &&
|
|
142
|
-
!isCurrentlyAnonymous &&
|
|
143
|
-
onUserConverted
|
|
144
|
-
) {
|
|
145
|
-
try {
|
|
146
|
-
await onUserConverted(previousUserId, currentUserId);
|
|
147
|
-
} catch {
|
|
148
|
-
// Migration failed but don't block user flow
|
|
125
|
+
onAuthStateChange: (user) => {
|
|
126
|
+
void (async () => {
|
|
127
|
+
if (!user) {
|
|
128
|
+
// User signed out
|
|
129
|
+
previousUserId = null;
|
|
130
|
+
wasAnonymous = false;
|
|
131
|
+
await onAuthStateChange?.(null);
|
|
132
|
+
return;
|
|
149
133
|
}
|
|
150
|
-
}
|
|
151
134
|
|
|
152
|
-
|
|
153
|
-
|
|
135
|
+
const currentUserId = user.uid;
|
|
136
|
+
const isCurrentlyAnonymous = user.isAnonymous ?? false;
|
|
137
|
+
|
|
138
|
+
// Detect anonymous-to-authenticated conversion
|
|
139
|
+
if (
|
|
140
|
+
previousUserId &&
|
|
141
|
+
previousUserId !== currentUserId &&
|
|
142
|
+
wasAnonymous &&
|
|
143
|
+
!isCurrentlyAnonymous &&
|
|
144
|
+
onUserConverted
|
|
145
|
+
) {
|
|
146
|
+
try {
|
|
147
|
+
await onUserConverted(previousUserId, currentUserId);
|
|
148
|
+
} catch {
|
|
149
|
+
// Migration failed but don't block user flow
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Create/update user document in Firestore
|
|
154
|
+
await ensureUserDocument(user);
|
|
154
155
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
156
|
+
// Update tracking state
|
|
157
|
+
previousUserId = currentUserId;
|
|
158
|
+
wasAnonymous = isCurrentlyAnonymous;
|
|
158
159
|
|
|
159
|
-
|
|
160
|
-
|
|
160
|
+
// Call app's custom callback
|
|
161
|
+
await onAuthStateChange?.(user);
|
|
162
|
+
})();
|
|
161
163
|
},
|
|
162
164
|
});
|
|
163
165
|
|
|
@@ -3,36 +3,45 @@
|
|
|
3
3
|
* Main container for auth screens with gradient and scroll
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import React from "react";
|
|
6
|
+
import React, { useMemo } from "react";
|
|
7
7
|
import {
|
|
8
8
|
View,
|
|
9
9
|
StyleSheet,
|
|
10
10
|
ScrollView,
|
|
11
11
|
KeyboardAvoidingView,
|
|
12
|
-
Platform,
|
|
13
12
|
} from "react-native";
|
|
14
13
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
14
|
+
import { useResponsive } from "@umituz/react-native-design-system";
|
|
15
15
|
import { AuthGradientBackground } from "./AuthGradientBackground";
|
|
16
16
|
|
|
17
|
+
/** Layout constants for auth screens */
|
|
18
|
+
const AUTH_LAYOUT = {
|
|
19
|
+
VERTICAL_PADDING: 40,
|
|
20
|
+
HORIZONTAL_PADDING: 20,
|
|
21
|
+
MAX_CONTENT_WIDTH: 440,
|
|
22
|
+
} as const;
|
|
23
|
+
|
|
17
24
|
interface AuthContainerProps {
|
|
18
25
|
children: React.ReactNode;
|
|
19
26
|
}
|
|
20
27
|
|
|
21
28
|
export const AuthContainer: React.FC<AuthContainerProps> = ({ children }) => {
|
|
22
29
|
const insets = useSafeAreaInsets();
|
|
30
|
+
const { spacingMultiplier } = useResponsive();
|
|
31
|
+
|
|
32
|
+
const dynamicStyles = useMemo(() => ({
|
|
33
|
+
paddingTop: insets.top + (AUTH_LAYOUT.VERTICAL_PADDING * spacingMultiplier),
|
|
34
|
+
paddingBottom: insets.bottom + (AUTH_LAYOUT.VERTICAL_PADDING * spacingMultiplier),
|
|
35
|
+
}), [insets.top, insets.bottom, spacingMultiplier]);
|
|
23
36
|
|
|
24
37
|
return (
|
|
25
38
|
<KeyboardAvoidingView
|
|
26
39
|
style={styles.container}
|
|
27
|
-
behavior=
|
|
28
|
-
keyboardVerticalOffset={Platform.OS === "ios" ? 0 : 20}
|
|
40
|
+
behavior="padding"
|
|
29
41
|
>
|
|
30
42
|
<AuthGradientBackground />
|
|
31
43
|
<ScrollView
|
|
32
|
-
contentContainerStyle={[
|
|
33
|
-
styles.scrollContent,
|
|
34
|
-
{ paddingTop: insets.top + 40, paddingBottom: insets.bottom + 40 },
|
|
35
|
-
]}
|
|
44
|
+
contentContainerStyle={[styles.scrollContent, dynamicStyles]}
|
|
36
45
|
keyboardShouldPersistTaps="handled"
|
|
37
46
|
showsVerticalScrollIndicator={false}
|
|
38
47
|
>
|
|
@@ -48,12 +57,12 @@ const styles = StyleSheet.create({
|
|
|
48
57
|
},
|
|
49
58
|
scrollContent: {
|
|
50
59
|
flexGrow: 1,
|
|
51
|
-
paddingHorizontal:
|
|
60
|
+
paddingHorizontal: AUTH_LAYOUT.HORIZONTAL_PADDING,
|
|
52
61
|
},
|
|
53
62
|
content: {
|
|
54
63
|
flex: 1,
|
|
55
64
|
justifyContent: "center",
|
|
56
|
-
maxWidth:
|
|
65
|
+
maxWidth: AUTH_LAYOUT.MAX_CONTENT_WIDTH,
|
|
57
66
|
alignSelf: "center",
|
|
58
67
|
width: "100%",
|
|
59
68
|
},
|
|
@@ -13,8 +13,6 @@ import {
|
|
|
13
13
|
type SocialAuthResult,
|
|
14
14
|
} from "@umituz/react-native-firebase";
|
|
15
15
|
|
|
16
|
-
declare const __DEV__: boolean;
|
|
17
|
-
|
|
18
16
|
export interface UseAppleAuthResult {
|
|
19
17
|
signInWithApple: () => Promise<SocialAuthResult>;
|
|
20
18
|
appleLoading: boolean;
|
|
@@ -38,18 +36,7 @@ export function useAppleAuth(): UseAppleAuthResult {
|
|
|
38
36
|
return { success: false, error: "Apple Sign-In is not available" };
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
if (__DEV__) {
|
|
42
|
-
// eslint-disable-next-line no-console
|
|
43
|
-
console.log("[useAppleAuth] Apple sign-in requested");
|
|
44
|
-
}
|
|
45
|
-
|
|
46
39
|
const result = await signInWithApple();
|
|
47
|
-
|
|
48
|
-
if (__DEV__) {
|
|
49
|
-
// eslint-disable-next-line no-console
|
|
50
|
-
console.log("[useAppleAuth] Apple sign-in result:", result);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
40
|
return result;
|
|
54
41
|
}, [appleAvailable, signInWithApple]);
|
|
55
42
|
|
|
@@ -14,8 +14,6 @@ import {
|
|
|
14
14
|
type SocialAuthResult,
|
|
15
15
|
} from "@umituz/react-native-firebase";
|
|
16
16
|
|
|
17
|
-
declare const __DEV__: boolean;
|
|
18
|
-
|
|
19
17
|
// Type declarations for expo-auth-session
|
|
20
18
|
interface GoogleAuthRequestConfig {
|
|
21
19
|
iosClientId: string;
|
|
@@ -59,11 +57,7 @@ try {
|
|
|
59
57
|
WebBrowser.maybeCompleteAuthSession();
|
|
60
58
|
}
|
|
61
59
|
} catch {
|
|
62
|
-
// expo-auth-session not available
|
|
63
|
-
if (__DEV__) {
|
|
64
|
-
// eslint-disable-next-line no-console
|
|
65
|
-
console.log("[useGoogleAuth] expo-auth-session not available");
|
|
66
|
-
}
|
|
60
|
+
// expo-auth-session not available - silent fallback
|
|
67
61
|
}
|
|
68
62
|
|
|
69
63
|
export interface GoogleAuthConfig {
|
|
@@ -118,11 +112,8 @@ export function useGoogleAuth(config?: GoogleAuthConfig): UseGoogleAuthResult {
|
|
|
118
112
|
if (idToken) {
|
|
119
113
|
setIsLoading(true);
|
|
120
114
|
signInWithGoogleToken(idToken)
|
|
121
|
-
.catch((
|
|
122
|
-
|
|
123
|
-
// eslint-disable-next-line no-console
|
|
124
|
-
console.error("[useGoogleAuth] Firebase sign-in error:", error);
|
|
125
|
-
}
|
|
115
|
+
.catch(() => {
|
|
116
|
+
// Silent error handling
|
|
126
117
|
})
|
|
127
118
|
.finally(() => {
|
|
128
119
|
setIsLoading(false);
|
|
@@ -152,12 +143,6 @@ export function useGoogleAuth(config?: GoogleAuthConfig): UseGoogleAuthResult {
|
|
|
152
143
|
const firebaseResult = await signInWithGoogleToken(
|
|
153
144
|
result.authentication.idToken,
|
|
154
145
|
);
|
|
155
|
-
|
|
156
|
-
if (__DEV__) {
|
|
157
|
-
// eslint-disable-next-line no-console
|
|
158
|
-
console.log("[useGoogleAuth] Sign-in successful:", firebaseResult);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
146
|
return firebaseResult;
|
|
162
147
|
}
|
|
163
148
|
|
|
@@ -22,8 +22,6 @@ import {
|
|
|
22
22
|
type SocialAuthResult,
|
|
23
23
|
} from "@umituz/react-native-firebase";
|
|
24
24
|
|
|
25
|
-
declare const __DEV__: boolean;
|
|
26
|
-
|
|
27
25
|
export interface UseSocialLoginConfig extends SocialAuthConfig {}
|
|
28
26
|
|
|
29
27
|
export interface UseSocialLoginResult {
|
|
@@ -64,11 +62,6 @@ export function useSocialLogin(config?: UseSocialLoginConfig): UseSocialLoginRes
|
|
|
64
62
|
return Promise.resolve({ success: false, error: "Google Sign-In is not configured" });
|
|
65
63
|
}
|
|
66
64
|
|
|
67
|
-
if (__DEV__) {
|
|
68
|
-
// eslint-disable-next-line no-console
|
|
69
|
-
console.log("[useSocialLogin] Use useGoogleAuth hook for Google OAuth flow");
|
|
70
|
-
}
|
|
71
|
-
|
|
72
65
|
return Promise.resolve({
|
|
73
66
|
success: false,
|
|
74
67
|
error: "Use useGoogleAuth hook for Google OAuth flow",
|
|
@@ -87,18 +80,7 @@ export function useSocialLogin(config?: UseSocialLoginConfig): UseSocialLoginRes
|
|
|
87
80
|
return { success: false, error: "Apple Sign-In is not available" };
|
|
88
81
|
}
|
|
89
82
|
|
|
90
|
-
if (__DEV__) {
|
|
91
|
-
// eslint-disable-next-line no-console
|
|
92
|
-
console.log("[useSocialLogin] Apple sign-in requested");
|
|
93
|
-
}
|
|
94
|
-
|
|
95
83
|
const result = await firebaseSignInWithApple();
|
|
96
|
-
|
|
97
|
-
if (__DEV__) {
|
|
98
|
-
// eslint-disable-next-line no-console
|
|
99
|
-
console.log("[useSocialLogin] Apple sign-in result:", result);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
84
|
return result;
|
|
103
85
|
}, [appleAvailable, firebaseSignInWithApple]);
|
|
104
86
|
|