@umituz/react-native-auth 3.1.4 → 3.1.6

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.1.4",
3
+ "version": "3.1.6",
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",
@@ -11,11 +11,16 @@ import { deleteCurrentUser } from "@umituz/react-native-firebase";
11
11
 
12
12
  export interface UseAccountManagementOptions {
13
13
  /**
14
- * Callback invoked when reauthentication is required
14
+ * Callback invoked when reauthentication is required (for Google/Apple)
15
15
  * App should show appropriate UI (Google/Apple sign-in) and return success status
16
16
  * If not provided, reauthentication errors will be thrown
17
17
  */
18
18
  onReauthRequired?: () => Promise<boolean>;
19
+ /**
20
+ * Callback invoked when password reauthentication is required (for email/password accounts)
21
+ * App should show password prompt and return the entered password, or null if cancelled
22
+ */
23
+ onPasswordRequired?: () => Promise<string | null>;
19
24
  }
20
25
 
21
26
  export interface UseAccountManagementReturn {
@@ -30,7 +35,7 @@ export const useAccountManagement = (
30
35
  ): UseAccountManagementReturn => {
31
36
  const { user, loading, signOut } = useAuth();
32
37
  const [isDeletingAccount, setIsDeletingAccount] = useState(false);
33
- const { onReauthRequired } = options;
38
+ const { onReauthRequired, onPasswordRequired } = options;
34
39
 
35
40
  const logout = useCallback(async () => {
36
41
  await signOut();
@@ -45,41 +50,124 @@ export const useAccountManagement = (
45
50
  throw new Error("Cannot delete anonymous account");
46
51
  }
47
52
 
53
+ if (__DEV__) {
54
+ console.log("[useAccountManagement] Starting delete account", {
55
+ userId: user.uid,
56
+ provider: user.provider,
57
+ });
58
+ }
59
+
48
60
  setIsDeletingAccount(true);
49
61
 
50
62
  try {
63
+ if (__DEV__) {
64
+ console.log("[useAccountManagement] Calling deleteCurrentUser with autoReauthenticate: true");
65
+ }
66
+
51
67
  const result = await deleteCurrentUser({ autoReauthenticate: true });
52
68
 
69
+ if (__DEV__) {
70
+ console.log("[useAccountManagement] First delete attempt result:", result);
71
+ }
72
+
53
73
  if (result.success) {
74
+ if (__DEV__) {
75
+ console.log("[useAccountManagement] ✅ Delete successful on first attempt");
76
+ }
54
77
  return;
55
78
  }
56
79
 
57
- // If reauthentication required and callback provided
58
- if (result.error?.requiresReauth && onReauthRequired) {
59
- const reauthSuccess = await onReauthRequired();
80
+ // If reauthentication required
81
+ if (result.error?.requiresReauth) {
82
+ // Handle password-based reauth
83
+ if (result.error.code === "auth/password-reauth-required" && onPasswordRequired) {
84
+ if (__DEV__) {
85
+ console.log("[useAccountManagement] Password reauth required, prompting user");
86
+ }
87
+
88
+ const password = await onPasswordRequired();
89
+
90
+ if (password) {
91
+ if (__DEV__) {
92
+ console.log("[useAccountManagement] Password provided, retrying delete");
93
+ }
94
+
95
+ const retryResult = await deleteCurrentUser({
96
+ autoReauthenticate: false,
97
+ password,
98
+ });
99
+
100
+ if (__DEV__) {
101
+ console.log("[useAccountManagement] Retry delete with password result:", retryResult);
102
+ }
103
+
104
+ if (retryResult.success) {
105
+ if (__DEV__) {
106
+ console.log("[useAccountManagement] ✅ Delete successful after password reauth");
107
+ }
108
+ return;
109
+ }
110
+
111
+ if (retryResult.error) {
112
+ throw new Error(retryResult.error.message);
113
+ }
114
+ } else {
115
+ if (__DEV__) {
116
+ console.log("[useAccountManagement] Password prompt cancelled");
117
+ }
118
+ throw new Error("Password required to delete account");
119
+ }
120
+ }
121
+
122
+ // Handle Google/Apple reauth
123
+ if (onReauthRequired) {
124
+ if (__DEV__) {
125
+ console.log("[useAccountManagement] Reauth required, calling onReauthRequired callback");
126
+ }
60
127
 
61
- if (reauthSuccess) {
62
- const retryResult = await deleteCurrentUser({
63
- autoReauthenticate: false,
64
- });
128
+ const reauthSuccess = await onReauthRequired();
65
129
 
66
- if (retryResult.success) {
67
- return;
130
+ if (__DEV__) {
131
+ console.log("[useAccountManagement] onReauthRequired result:", reauthSuccess);
68
132
  }
69
133
 
70
- if (retryResult.error) {
71
- throw new Error(retryResult.error.message);
134
+ if (reauthSuccess) {
135
+ if (__DEV__) {
136
+ console.log("[useAccountManagement] Retrying delete after reauth");
137
+ }
138
+
139
+ const retryResult = await deleteCurrentUser({
140
+ autoReauthenticate: false,
141
+ });
142
+
143
+ if (__DEV__) {
144
+ console.log("[useAccountManagement] Retry delete result:", retryResult);
145
+ }
146
+
147
+ if (retryResult.success) {
148
+ if (__DEV__) {
149
+ console.log("[useAccountManagement] ✅ Delete successful after reauth");
150
+ }
151
+ return;
152
+ }
153
+
154
+ if (retryResult.error) {
155
+ throw new Error(retryResult.error.message);
156
+ }
72
157
  }
73
158
  }
74
159
  }
75
160
 
76
161
  if (result.error) {
162
+ if (__DEV__) {
163
+ console.log("[useAccountManagement] ❌ Delete failed:", result.error);
164
+ }
77
165
  throw new Error(result.error.message);
78
166
  }
79
167
  } finally {
80
168
  setIsDeletingAccount(false);
81
169
  }
82
- }, [user, onReauthRequired]);
170
+ }, [user, onReauthRequired, onPasswordRequired]);
83
171
 
84
172
  return {
85
173
  logout,