@umituz/react-native-auth 3.4.20 → 3.4.22

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-auth",
3
- "version": "3.4.20",
3
+ "version": "3.4.22",
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",
package/src/index.ts CHANGED
@@ -172,6 +172,9 @@ export type { UseGoogleAuthResult, GoogleAuthConfig as GoogleAuthHookConfig } fr
172
172
  export { useAppleAuth } from './presentation/hooks/useAppleAuth';
173
173
  export type { UseAppleAuthResult } from './presentation/hooks/useAppleAuth';
174
174
 
175
+ export { useAuthBottomSheet } from './presentation/hooks/useAuthBottomSheet';
176
+ export type { SocialAuthConfiguration } from './presentation/hooks/useAuthBottomSheet';
177
+
175
178
  export type { UserProfile, UpdateProfileParams } from './domain/entities/UserProfile';
176
179
 
177
180
  // Domain Utils - Anonymous Names
@@ -216,11 +219,6 @@ export { PasswordMatchIndicator } from './presentation/components/PasswordMatchI
216
219
  export type { PasswordMatchIndicatorProps } from './presentation/components/PasswordMatchIndicator';
217
220
  export { AuthBottomSheet } from './presentation/components/AuthBottomSheet';
218
221
  export type { AuthBottomSheetProps } from './presentation/components/AuthBottomSheet';
219
- export { AuthBottomSheetWrapper } from './presentation/components/AuthBottomSheetWrapper';
220
- export type {
221
- AuthBottomSheetWrapperProps,
222
- SocialAuthConfiguration,
223
- } from './presentation/components/AuthBottomSheetWrapper';
224
222
  export { SocialLoginButtons } from './presentation/components/SocialLoginButtons';
225
223
  export type { SocialLoginButtonsProps } from './presentation/components/SocialLoginButtons';
226
224
  export { ProfileSection } from './presentation/components/ProfileSection';
@@ -3,7 +3,7 @@
3
3
  * Bottom sheet modal for authentication (Login/Register)
4
4
  */
5
5
 
6
- import React, { useEffect, useCallback, useRef, useState } from "react";
6
+ import React from "react";
7
7
  import { View, TouchableOpacity, ScrollView } from "react-native";
8
8
  import {
9
9
  useAppDesignTokens,
@@ -11,27 +11,24 @@ import {
11
11
  AtomicIcon,
12
12
  AtomicKeyboardAvoidingView,
13
13
  BottomSheetModal,
14
- type BottomSheetModalRef,
15
14
  } from "@umituz/react-native-design-system";
16
15
  import { useLocalization } from "@umituz/react-native-localization";
17
- import { useAuthModalStore } from "../stores/authModalStore";
18
- import { useAuth } from "../hooks/useAuth";
16
+ import { useAuthBottomSheet, type SocialAuthConfiguration } from "../hooks/useAuthBottomSheet";
19
17
  import { LoginForm } from "./LoginForm";
20
18
  import { RegisterForm } from "./RegisterForm";
21
19
  import { SocialLoginButtons } from "./SocialLoginButtons";
22
20
  import { styles } from "./AuthBottomSheet.styles";
23
- import type { SocialAuthProvider } from "../../domain/value-objects/AuthConfig";
24
21
 
25
22
  export interface AuthBottomSheetProps {
26
23
  termsUrl?: string;
27
24
  privacyUrl?: string;
28
25
  onTermsPress?: () => void;
29
26
  onPrivacyPress?: () => void;
30
- /** Enabled social auth providers */
31
- socialProviders?: SocialAuthProvider[];
32
- /** Called when Google sign-in is requested */
27
+ /** Social auth configuration */
28
+ socialConfig?: SocialAuthConfiguration;
29
+ /** Called when Google sign-in is requested (overrides internal behavior) */
33
30
  onGoogleSignIn?: () => Promise<void>;
34
- /** Called when Apple sign-in is requested */
31
+ /** Called when Apple sign-in is requested (overrides internal behavior) */
35
32
  onAppleSignIn?: () => Promise<void>;
36
33
  }
37
34
 
@@ -40,86 +37,26 @@ export const AuthBottomSheet: React.FC<AuthBottomSheetProps> = ({
40
37
  privacyUrl,
41
38
  onTermsPress,
42
39
  onPrivacyPress,
43
- socialProviders = [],
40
+ socialConfig,
44
41
  onGoogleSignIn,
45
42
  onAppleSignIn,
46
43
  }) => {
47
44
  const tokens = useAppDesignTokens();
48
45
  const { t } = useLocalization();
49
- const modalRef = useRef<BottomSheetModalRef>(null);
50
46
 
51
- const [googleLoading, setGoogleLoading] = useState(false);
52
- const [appleLoading, setAppleLoading] = useState(false);
53
-
54
- const { isVisible, mode, hideAuthModal, setMode, executePendingCallback, clearPendingCallback } =
55
- useAuthModalStore();
56
- const { isAuthenticated, isAnonymous } = useAuth();
57
-
58
- useEffect(() => {
59
- if (isVisible) {
60
- modalRef.current?.present();
61
- } else {
62
- modalRef.current?.dismiss();
63
- }
64
- }, [isVisible]);
65
-
66
- const handleDismiss = useCallback(() => {
67
- hideAuthModal();
68
- clearPendingCallback();
69
- }, [hideAuthModal, clearPendingCallback]);
70
-
71
- const handleClose = useCallback(() => {
72
- modalRef.current?.dismiss();
73
- handleDismiss();
74
- }, [handleDismiss]);
75
-
76
- const prevIsAuthenticatedRef = useRef(isAuthenticated);
77
- const prevIsVisibleRef = useRef(isVisible);
78
-
79
- useEffect(() => {
80
- // Only close the modal if the user was NOT authenticated and then BECOMES authenticated
81
- // while the modal is visible.
82
- if (!prevIsAuthenticatedRef.current && isAuthenticated && isVisible && !isAnonymous) {
83
- if (typeof __DEV__ !== "undefined" && __DEV__) {
84
- // eslint-disable-next-line no-console
85
- console.log("[AuthBottomSheet] Auto-closing due to successful authentication transition");
86
- }
87
- handleClose();
88
- executePendingCallback();
89
- }
90
-
91
- // Update ref for next render
92
- prevIsAuthenticatedRef.current = isAuthenticated;
93
- prevIsVisibleRef.current = isVisible;
94
- }, [isAuthenticated, isVisible, isAnonymous, executePendingCallback, handleClose]);
95
-
96
- const handleNavigateToRegister = useCallback(() => {
97
- setMode("register");
98
- }, [setMode]);
99
-
100
- const handleNavigateToLogin = useCallback(() => {
101
- setMode("login");
102
- }, [setMode]);
103
-
104
- const handleGoogleSignIn = useCallback(async () => {
105
- if (!onGoogleSignIn) return;
106
- setGoogleLoading(true);
107
- try {
108
- await onGoogleSignIn();
109
- } finally {
110
- setGoogleLoading(false);
111
- }
112
- }, [onGoogleSignIn]);
113
-
114
- const handleAppleSignIn = useCallback(async () => {
115
- if (!onAppleSignIn) return;
116
- setAppleLoading(true);
117
- try {
118
- await onAppleSignIn();
119
- } finally {
120
- setAppleLoading(false);
121
- }
122
- }, [onAppleSignIn]);
47
+ const {
48
+ modalRef,
49
+ googleLoading,
50
+ appleLoading,
51
+ mode,
52
+ providers,
53
+ handleDismiss,
54
+ handleClose,
55
+ handleNavigateToRegister,
56
+ handleNavigateToLogin,
57
+ handleGoogleSignIn,
58
+ handleAppleSignIn,
59
+ } = useAuthBottomSheet({ socialConfig, onGoogleSignIn, onAppleSignIn });
123
60
 
124
61
  return (
125
62
  <BottomSheetModal
@@ -131,11 +68,6 @@ export const AuthBottomSheet: React.FC<AuthBottomSheetProps> = ({
131
68
  <AtomicKeyboardAvoidingView
132
69
  style={{ flex: 1 }}
133
70
  >
134
- <ScrollView
135
- contentContainerStyle={styles.scrollContent}
136
- showsVerticalScrollIndicator={false}
137
- keyboardShouldPersistTaps="handled"
138
- >
139
71
  <TouchableOpacity
140
72
  style={styles.closeButton}
141
73
  onPress={handleClose}
@@ -146,6 +78,12 @@ export const AuthBottomSheet: React.FC<AuthBottomSheetProps> = ({
146
78
  <AtomicIcon name="close" size="md" color="secondary" />
147
79
  </TouchableOpacity>
148
80
 
81
+ <ScrollView
82
+ contentContainerStyle={styles.scrollContent}
83
+ showsVerticalScrollIndicator={false}
84
+ keyboardShouldPersistTaps="handled"
85
+ >
86
+
149
87
  <View style={styles.header}>
150
88
  <AtomicText type="headlineLarge" color="primary" style={styles.title}>
151
89
  {mode === "login" ? t("auth.signIn") : t("auth.createAccount")}
@@ -168,9 +106,9 @@ export const AuthBottomSheet: React.FC<AuthBottomSheetProps> = ({
168
106
  />
169
107
  )}
170
108
 
171
- {socialProviders.length > 0 && (
109
+ {providers.length > 0 && (
172
110
  <SocialLoginButtons
173
- enabledProviders={socialProviders}
111
+ enabledProviders={providers}
174
112
  onGooglePress={() => { void handleGoogleSignIn(); }}
175
113
  onApplePress={() => { void handleAppleSignIn(); }}
176
114
  googleLoading={googleLoading}
@@ -0,0 +1,144 @@
1
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
2
+ import { Platform } from "react-native";
3
+ import type { BottomSheetModalRef } from "@umituz/react-native-design-system";
4
+ import { useAuthModalStore } from "../stores/authModalStore";
5
+ import { useAuth } from "../hooks/useAuth";
6
+ import { useGoogleAuth, type GoogleAuthConfig } from "./useGoogleAuth";
7
+ import { useAppleAuth } from "./useAppleAuth";
8
+ import type { SocialAuthProvider } from "../../domain/value-objects/AuthConfig";
9
+
10
+ declare const __DEV__: boolean;
11
+
12
+ export interface SocialAuthConfiguration {
13
+ google?: GoogleAuthConfig;
14
+ apple?: { enabled: boolean };
15
+ }
16
+
17
+ interface UseAuthBottomSheetParams {
18
+ socialConfig?: SocialAuthConfiguration;
19
+ onGoogleSignIn?: () => Promise<void>;
20
+ onAppleSignIn?: () => Promise<void>;
21
+ }
22
+
23
+ export function useAuthBottomSheet(params: UseAuthBottomSheetParams = {}) {
24
+ const { socialConfig, onGoogleSignIn, onAppleSignIn } = params;
25
+
26
+ const modalRef = useRef<BottomSheetModalRef>(null);
27
+ const [googleLoading, setGoogleLoading] = useState(false);
28
+ const [appleLoading, setAppleLoading] = useState(false);
29
+
30
+ const { isVisible, mode, hideAuthModal, setMode, executePendingCallback, clearPendingCallback } =
31
+ useAuthModalStore();
32
+ const { isAuthenticated, isAnonymous } = useAuth();
33
+
34
+ // Social Auth Hooks
35
+ const { signInWithGoogle, googleConfigured } = useGoogleAuth(socialConfig?.google);
36
+ const { signInWithApple, appleAvailable } = useAppleAuth();
37
+
38
+ // Determine enabled providers
39
+ const providers = useMemo<SocialAuthProvider[]>(() => {
40
+ const result: SocialAuthProvider[] = [];
41
+
42
+ if (Platform.OS === "ios" && socialConfig?.apple?.enabled && appleAvailable) {
43
+ result.push("apple");
44
+ }
45
+
46
+ if (googleConfigured) {
47
+ result.push("google");
48
+ }
49
+
50
+ return result;
51
+ }, [socialConfig?.apple?.enabled, appleAvailable, googleConfigured]);
52
+
53
+ // Handle visibility sync with modalRef
54
+ useEffect(() => {
55
+ if (isVisible) {
56
+ modalRef.current?.present();
57
+ } else {
58
+ modalRef.current?.dismiss();
59
+ }
60
+ }, [isVisible]);
61
+
62
+ const handleDismiss = useCallback(() => {
63
+ hideAuthModal();
64
+ clearPendingCallback();
65
+ }, [hideAuthModal, clearPendingCallback]);
66
+
67
+ const handleClose = useCallback(() => {
68
+ modalRef.current?.dismiss();
69
+ handleDismiss();
70
+ }, [handleDismiss]);
71
+
72
+ const prevIsAuthenticatedRef = useRef(isAuthenticated);
73
+ const prevIsVisibleRef = useRef(isVisible);
74
+ const prevIsAnonymousRef = useRef(isAnonymous);
75
+
76
+ useEffect(() => {
77
+ const justAuthenticated = !prevIsAuthenticatedRef.current && isAuthenticated;
78
+ const justConvertedFromAnonymous = prevIsAnonymousRef.current && !isAnonymous && isAuthenticated;
79
+
80
+ if ((justAuthenticated || justConvertedFromAnonymous) && isVisible && !isAnonymous) {
81
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
82
+ // eslint-disable-next-line no-console
83
+ console.log("[useAuthBottomSheet] Auto-closing due to successful authentication transition", {
84
+ justAuthenticated,
85
+ justConvertedFromAnonymous,
86
+ });
87
+ }
88
+ handleClose();
89
+ executePendingCallback();
90
+ }
91
+
92
+ prevIsAuthenticatedRef.current = isAuthenticated;
93
+ prevIsVisibleRef.current = isVisible;
94
+ prevIsAnonymousRef.current = isAnonymous;
95
+ }, [isAuthenticated, isVisible, isAnonymous, executePendingCallback, handleClose]);
96
+
97
+ const handleNavigateToRegister = useCallback(() => {
98
+ setMode("register");
99
+ }, [setMode]);
100
+
101
+ const handleNavigateToLogin = useCallback(() => {
102
+ setMode("login");
103
+ }, [setMode]);
104
+
105
+ const handleGoogleSignInInternal = useCallback(async () => {
106
+ setGoogleLoading(true);
107
+ try {
108
+ if (onGoogleSignIn) {
109
+ await onGoogleSignIn();
110
+ } else if (signInWithGoogle) {
111
+ await signInWithGoogle();
112
+ }
113
+ } finally {
114
+ setGoogleLoading(false);
115
+ }
116
+ }, [onGoogleSignIn, signInWithGoogle]);
117
+
118
+ const handleAppleSignInInternal = useCallback(async () => {
119
+ setAppleLoading(true);
120
+ try {
121
+ if (onAppleSignIn) {
122
+ await onAppleSignIn();
123
+ } else if (signInWithApple) {
124
+ await signInWithApple();
125
+ }
126
+ } finally {
127
+ setAppleLoading(false);
128
+ }
129
+ }, [onAppleSignIn, signInWithApple]);
130
+
131
+ return {
132
+ modalRef,
133
+ googleLoading,
134
+ appleLoading,
135
+ mode,
136
+ providers,
137
+ handleDismiss,
138
+ handleClose,
139
+ handleNavigateToRegister,
140
+ handleNavigateToLogin,
141
+ handleGoogleSignIn: handleGoogleSignInInternal,
142
+ handleAppleSignIn: handleAppleSignInInternal,
143
+ };
144
+ }
@@ -1,115 +0,0 @@
1
- /**
2
- * AuthBottomSheetWrapper Component
3
- * Self-contained auth modal with integrated social login
4
- *
5
- * This wrapper component combines AuthBottomSheet with social auth hooks,
6
- * providing a complete authentication solution for apps.
7
- *
8
- * Usage:
9
- * ```tsx
10
- * <AuthBottomSheetWrapper
11
- * termsUrl="https://myapp.com/terms"
12
- * privacyUrl="https://myapp.com/privacy"
13
- * socialConfig={{
14
- * google: { webClientId: '...', iosClientId: '...' },
15
- * apple: { enabled: true }
16
- * }}
17
- * />
18
- * ```
19
- */
20
-
21
- import React, { useCallback, useMemo } from "react";
22
- import { Platform } from "react-native";
23
- import { AuthBottomSheet } from "./AuthBottomSheet";
24
- import { useGoogleAuth, type GoogleAuthConfig } from "../hooks/useGoogleAuth";
25
- import { useAppleAuth } from "../hooks/useAppleAuth";
26
- import type { SocialAuthProvider } from "../../domain/value-objects/AuthConfig";
27
-
28
- declare const __DEV__: boolean;
29
-
30
- export interface SocialAuthConfiguration {
31
- google?: GoogleAuthConfig;
32
- apple?: { enabled: boolean };
33
- }
34
-
35
- export interface AuthBottomSheetWrapperProps {
36
- /** Terms of Service URL */
37
- termsUrl?: string;
38
- /** Privacy Policy URL */
39
- privacyUrl?: string;
40
- /** Called when Terms link is pressed (overrides default behavior) */
41
- onTermsPress?: () => void;
42
- /** Called when Privacy link is pressed (overrides default behavior) */
43
- onPrivacyPress?: () => void;
44
- /** Social auth configuration */
45
- socialConfig?: SocialAuthConfiguration;
46
- }
47
-
48
- /**
49
- * Self-contained auth bottom sheet with integrated social login
50
- */
51
- export const AuthBottomSheetWrapper: React.FC<AuthBottomSheetWrapperProps> = ({
52
- termsUrl,
53
- privacyUrl,
54
- onTermsPress,
55
- onPrivacyPress,
56
- socialConfig,
57
- }) => {
58
- const { signInWithGoogle, googleConfigured } = useGoogleAuth(socialConfig?.google);
59
- const { signInWithApple, appleAvailable } = useAppleAuth();
60
-
61
- const providers = useMemo<SocialAuthProvider[]>(() => {
62
- const result: SocialAuthProvider[] = [];
63
-
64
- if (Platform.OS === "ios" && socialConfig?.apple?.enabled && appleAvailable) {
65
- result.push("apple");
66
- }
67
-
68
- if (googleConfigured) {
69
- result.push("google");
70
- }
71
-
72
- if (__DEV__) {
73
- // eslint-disable-next-line no-console
74
- console.log("[AuthBottomSheetWrapper] Enabled providers:", result);
75
- }
76
-
77
- return result;
78
- }, [socialConfig?.apple?.enabled, appleAvailable, googleConfigured]);
79
-
80
- const handleGoogleSignIn = useCallback(async () => {
81
- if (__DEV__) {
82
- // eslint-disable-next-line no-console
83
- console.log("[AuthBottomSheetWrapper] Google sign-in requested");
84
- }
85
- const result = await signInWithGoogle();
86
- if (__DEV__) {
87
- // eslint-disable-next-line no-console
88
- console.log("[AuthBottomSheetWrapper] Google result:", result);
89
- }
90
- }, [signInWithGoogle]);
91
-
92
- const handleAppleSignIn = useCallback(async () => {
93
- if (__DEV__) {
94
- // eslint-disable-next-line no-console
95
- console.log("[AuthBottomSheetWrapper] Apple sign-in requested");
96
- }
97
- const result = await signInWithApple();
98
- if (__DEV__) {
99
- // eslint-disable-next-line no-console
100
- console.log("[AuthBottomSheetWrapper] Apple result:", result);
101
- }
102
- }, [signInWithApple]);
103
-
104
- return (
105
- <AuthBottomSheet
106
- termsUrl={termsUrl}
107
- privacyUrl={privacyUrl}
108
- onTermsPress={onTermsPress}
109
- onPrivacyPress={onPrivacyPress}
110
- socialProviders={providers}
111
- onGoogleSignIn={handleGoogleSignIn}
112
- onAppleSignIn={handleAppleSignIn}
113
- />
114
- );
115
- };