@umituz/react-native-auth 4.2.7 → 4.2.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-auth",
3
- "version": "4.2.7",
3
+ "version": "4.2.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",
package/src/index.ts CHANGED
@@ -62,7 +62,7 @@ export type { UseAppleAuthResult } from './presentation/hooks/useAppleAuth';
62
62
  export { useAuthBottomSheet } from './presentation/hooks/useAuthBottomSheet';
63
63
  export type { SocialAuthConfiguration } from './presentation/hooks/useAuthBottomSheet';
64
64
  export { useAuthHandlers } from './presentation/hooks/useAuthHandlers';
65
- export type { AuthHandlersAppInfo, AuthHandlersTranslations } from './presentation/hooks/useAuthHandlers';
65
+ export type { AuthHandlersAppInfo, AuthHandlersTranslations, AuthHandlersOptions } from './presentation/hooks/useAuthHandlers';
66
66
  export { usePasswordPromptNavigation } from './presentation/hooks/usePasswordPromptNavigation';
67
67
  export type { UsePasswordPromptNavigationOptions, UsePasswordPromptNavigationReturn } from './presentation/hooks/usePasswordPromptNavigation';
68
68
 
@@ -31,7 +31,15 @@ export interface AuthHandlersTranslations {
31
31
  deleteAccountError?: string;
32
32
  }
33
33
 
34
- export const useAuthHandlers = (appInfo: AuthHandlersAppInfo, translations?: AuthHandlersTranslations) => {
34
+ export interface AuthHandlersOptions {
35
+ onBeforeDeleteAccount?: () => void;
36
+ }
37
+
38
+ export const useAuthHandlers = (
39
+ appInfo: AuthHandlersAppInfo,
40
+ translations?: AuthHandlersTranslations,
41
+ options?: AuthHandlersOptions,
42
+ ) => {
35
43
  const { signOut } = useAuth();
36
44
  const { showAuthModal } = useAuthModalStore();
37
45
 
@@ -90,6 +98,10 @@ export const useAuthHandlers = (appInfo: AuthHandlersAppInfo, translations?: Aut
90
98
  console.log("[useAuthHandlers] handleDeleteAccount called");
91
99
  }
92
100
  try {
101
+ if (options?.onBeforeDeleteAccount) {
102
+ options.onBeforeDeleteAccount();
103
+ }
104
+
93
105
  if (typeof __DEV__ !== "undefined" && __DEV__) {
94
106
  console.log("[useAuthHandlers] Calling deleteAccountFromAuth...");
95
107
  }
@@ -107,7 +119,7 @@ export const useAuthHandlers = (appInfo: AuthHandlersAppInfo, translations?: Aut
107
119
  errorMessage || translations?.deleteAccountError || "Failed to delete account"
108
120
  );
109
121
  }
110
- }, [deleteAccountFromAuth, translations]);
122
+ }, [deleteAccountFromAuth, translations, options]);
111
123
 
112
124
  const handleSignIn = useCallback(() => {
113
125
  showAuthModal(undefined, "login");
@@ -1,11 +1,6 @@
1
- /**
2
- * Password Prompt Navigation Hook
3
- * Navigation-based password prompt that maintains Promise interface
4
- * Uses AppNavigation for global navigation access
5
- */
6
-
7
- import { useCallback, useRef, useEffect } from 'react';
1
+ import { useCallback } from 'react';
8
2
  import { AppNavigation } from '@umituz/react-native-design-system';
3
+ import { setPasswordPromptCallback } from '../utils/passwordPromptCallback';
9
4
 
10
5
  declare const __DEV__: boolean;
11
6
 
@@ -24,55 +19,22 @@ export const usePasswordPromptNavigation = (
24
19
  options: UsePasswordPromptNavigationOptions
25
20
  ): UsePasswordPromptNavigationReturn => {
26
21
  const { title, message, confirmText, cancelText } = options;
27
- const resolveRef = useRef<((value: string | null) => void) | null>(null);
28
-
29
- useEffect(() => {
30
- return () => {
31
- if (resolveRef.current) {
32
- resolveRef.current(null);
33
- resolveRef.current = null;
34
- }
35
- };
36
- }, []);
37
22
 
38
23
  const showPasswordPrompt = useCallback((): Promise<string | null> => {
39
24
  if (typeof __DEV__ !== "undefined" && __DEV__) {
40
25
  console.log("[showPasswordPrompt] Called");
41
26
  }
42
27
 
43
- return new Promise<string | null>((resolve, reject) => {
44
- if (resolveRef.current) {
45
- if (typeof __DEV__ !== "undefined" && __DEV__) {
46
- console.log("[showPasswordPrompt] Resolving previous promise with null");
47
- }
48
- resolveRef.current(null);
49
- }
50
-
51
- resolveRef.current = resolve;
52
-
53
- const params = {
54
- onComplete: (password: string | null) => {
55
- if (typeof __DEV__ !== "undefined" && __DEV__) {
56
- console.log("[showPasswordPrompt] onComplete called with:", password ? "password" : "null");
57
- }
58
- if (resolveRef.current) {
59
- resolveRef.current(password);
60
- resolveRef.current = null;
61
- }
62
- },
63
- title,
64
- message,
65
- confirmText,
66
- cancelText,
67
- };
28
+ return new Promise<string | null>((resolve) => {
29
+ setPasswordPromptCallback(resolve);
68
30
 
69
31
  try {
70
- if (typeof __DEV__ !== "undefined" && __DEV__) {
71
- console.log("[showPasswordPrompt] Navigating to PasswordPrompt");
72
- }
73
-
74
- AppNavigation.navigate('PasswordPrompt', params);
75
-
32
+ AppNavigation.navigate('PasswordPrompt', {
33
+ title,
34
+ message,
35
+ confirmText,
36
+ cancelText,
37
+ });
76
38
  if (typeof __DEV__ !== "undefined" && __DEV__) {
77
39
  console.log("[showPasswordPrompt] Navigation called successfully");
78
40
  }
@@ -80,16 +42,11 @@ export const usePasswordPromptNavigation = (
80
42
  if (typeof __DEV__ !== "undefined" && __DEV__) {
81
43
  console.error("[showPasswordPrompt] Navigation failed:", error);
82
44
  }
83
- if (resolveRef.current) {
84
- resolveRef.current(null);
85
- resolveRef.current = null;
86
- }
87
- reject(error);
45
+ setPasswordPromptCallback(null);
46
+ resolve(null);
88
47
  }
89
48
  });
90
49
  }, [title, message, confirmText, cancelText]);
91
50
 
92
- return {
93
- showPasswordPrompt,
94
- };
51
+ return { showPasswordPrompt };
95
52
  };
@@ -1,9 +1,4 @@
1
- /**
2
- * Password Prompt Screen
3
- * Navigation screen for password input during account deletion reauthentication
4
- */
5
-
6
- import React, { useState, useEffect } from 'react';
1
+ import React, { useState } from 'react';
7
2
  import { View, StyleSheet, KeyboardAvoidingView, Platform, TouchableOpacity } from 'react-native';
8
3
  import {
9
4
  AtomicInput,
@@ -13,11 +8,11 @@ import {
13
8
  SafeAreaView,
14
9
  useAppDesignTokens
15
10
  } from '@umituz/react-native-design-system';
11
+ import { resolvePasswordPrompt } from '../utils/passwordPromptCallback';
16
12
 
17
13
  export interface PasswordPromptScreenProps {
18
14
  route: {
19
15
  params: {
20
- onComplete: (password: string | null) => void;
21
16
  title?: string;
22
17
  message?: string;
23
18
  confirmText?: string;
@@ -38,30 +33,23 @@ export const PasswordPromptScreen: React.FC<PasswordPromptScreenProps> = ({
38
33
  const [error, setError] = useState('');
39
34
 
40
35
  const {
41
- onComplete,
42
36
  title = 'Password Required',
43
37
  message = 'Enter your password to continue',
44
38
  confirmText = 'Confirm',
45
39
  cancelText = 'Cancel',
46
40
  } = route.params;
47
41
 
48
- useEffect(() => {
49
- return () => {
50
- onComplete(null);
51
- };
52
- }, [onComplete]);
53
-
54
42
  const handleConfirm = () => {
55
43
  if (!password.trim()) {
56
44
  setError('Password is required');
57
45
  return;
58
46
  }
59
- onComplete(password);
47
+ resolvePasswordPrompt(password);
60
48
  navigation.goBack();
61
49
  };
62
50
 
63
51
  const handleCancel = () => {
64
- onComplete(null);
52
+ resolvePasswordPrompt(null);
65
53
  navigation.goBack();
66
54
  };
67
55
 
@@ -0,0 +1,14 @@
1
+ let callback: ((value: string | null) => void) | null = null;
2
+
3
+ export const setPasswordPromptCallback = (cb: ((value: string | null) => void) | null): void => {
4
+ callback = cb;
5
+ };
6
+
7
+ export const getPasswordPromptCallback = (): ((value: string | null) => void) | null => callback;
8
+
9
+ export const resolvePasswordPrompt = (value: string | null): void => {
10
+ if (callback) {
11
+ callback(value);
12
+ callback = null;
13
+ }
14
+ };