@umituz/react-native-auth 3.6.90 → 3.6.92

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.6.90",
3
+ "version": "3.6.92",
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",
@@ -6,7 +6,7 @@
6
6
  import { useCallback, useState } from "react";
7
7
  import { Alert } from "react-native";
8
8
  import { useAuth } from "./useAuth";
9
- import { handleAccountDeletion } from "../utils/accountDeleteHandler.util";
9
+ import { deleteCurrentUser } from "@umituz/react-native-firebase";
10
10
 
11
11
  export interface UseAccountManagementOptions {
12
12
  /**
@@ -111,14 +111,56 @@ export const useAccountManagement = (
111
111
  setIsDeletingAccount(true);
112
112
 
113
113
  try {
114
- await handleAccountDeletion({
115
- onReauthRequired,
116
- onPasswordRequired: passwordHandler,
117
- });
114
+ // First attempt - Firebase will check if reauthentication is needed
115
+ const result = await deleteCurrentUser({ autoReauthenticate: true });
116
+
117
+ if (result.success) {
118
+ return;
119
+ }
120
+
121
+ // Handle password reauthentication
122
+ if (result.error?.code === "auth/password-reauth") {
123
+ const password = await passwordHandler();
124
+ if (!password) {
125
+ throw new Error("Password required to delete account");
126
+ }
127
+
128
+ // Retry with password
129
+ const retryResult = await deleteCurrentUser({
130
+ autoReauthenticate: true,
131
+ password,
132
+ });
133
+
134
+ if (!retryResult.success) {
135
+ throw new Error(retryResult.error?.message || "Failed to delete account");
136
+ }
137
+
138
+ return;
139
+ }
140
+
141
+ // Handle social auth reauthentication
142
+ if (result.error?.requiresReauth && onReauthRequired) {
143
+ const reauthSuccess = await onReauthRequired();
144
+ if (!reauthSuccess) {
145
+ throw new Error("Reauthentication required to delete account");
146
+ }
147
+
148
+ // Retry after social reauth
149
+ const retryResult = await deleteCurrentUser({ autoReauthenticate: true });
150
+
151
+ if (!retryResult.success) {
152
+ throw new Error(retryResult.error?.message || "Failed to delete account");
153
+ }
154
+
155
+ return;
156
+ }
157
+
158
+ // Other errors
159
+ throw new Error(result.error?.message || "Failed to delete account");
118
160
  } finally {
119
161
  setIsDeletingAccount(false);
120
162
  }
121
- }, [user, onReauthRequired, passwordHandler]);
163
+ }, [user, passwordHandler, onReauthRequired]);
122
164
 
123
165
  return {
124
166
  logout,
@@ -1,96 +0,0 @@
1
- /**
2
- * Account Delete Handler Utility
3
- * Handles reauthentication flow for account deletion
4
- */
5
-
6
- import { deleteCurrentUser } from "@umituz/react-native-firebase";
7
-
8
- export interface DeleteAccountCallbacks {
9
- onReauthRequired?: () => Promise<boolean>;
10
- onPasswordRequired?: () => Promise<string | null>;
11
- }
12
-
13
- export interface DeleteAccountOptions {
14
- autoReauthenticate: boolean;
15
- password?: string;
16
- }
17
-
18
- /**
19
- * Handles account deletion with reauthentication retry logic
20
- */
21
- export async function handleAccountDeletion(
22
- callbacks: DeleteAccountCallbacks
23
- ): Promise<void> {
24
- const result = await deleteCurrentUser({ autoReauthenticate: true });
25
-
26
- if (result.success) {
27
- return;
28
- }
29
-
30
- if (result.error?.requiresReauth) {
31
- await handleReauthentication(result, callbacks);
32
- return;
33
- }
34
-
35
- if (result.error) {
36
- throw new Error(result.error.message);
37
- }
38
- }
39
-
40
- async function handleReauthentication(
41
- initialResult: Awaited<ReturnType<typeof deleteCurrentUser>>,
42
- callbacks: DeleteAccountCallbacks
43
- ): Promise<void> {
44
- const { onReauthRequired, onPasswordRequired } = callbacks;
45
-
46
- // Handle password reauth
47
- if (initialResult.error?.code === "auth/password-reauth" && onPasswordRequired) {
48
- await retryWithPassword(onPasswordRequired);
49
- return;
50
- }
51
-
52
- // Handle social auth reauth
53
- if (onReauthRequired) {
54
- await retryWithSocialAuth(onReauthRequired);
55
- return;
56
- }
57
- }
58
-
59
- async function retryWithPassword(onPasswordRequired: () => Promise<string | null>): Promise<void> {
60
- const password = await onPasswordRequired();
61
-
62
- if (!password) {
63
- throw new Error("Password required to delete account");
64
- }
65
-
66
- const result = await deleteCurrentUser({
67
- autoReauthenticate: false,
68
- password,
69
- });
70
-
71
- if (result.success) {
72
- return;
73
- }
74
-
75
- if (result.error) {
76
- throw new Error(result.error.message);
77
- }
78
- }
79
-
80
- async function retryWithSocialAuth(onReauthRequired: () => Promise<boolean>): Promise<void> {
81
- const reauthSuccess = await onReauthRequired();
82
-
83
- if (!reauthSuccess) {
84
- throw new Error("Reauthentication required to delete account");
85
- }
86
-
87
- const result = await deleteCurrentUser({ autoReauthenticate: false });
88
-
89
- if (result.success) {
90
- return;
91
- }
92
-
93
- if (result.error) {
94
- throw new Error(result.error.message);
95
- }
96
- }