@umituz/react-native-auth 3.1.5 → 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.
|
|
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();
|
|
@@ -72,40 +77,83 @@ export const useAccountManagement = (
|
|
|
72
77
|
return;
|
|
73
78
|
}
|
|
74
79
|
|
|
75
|
-
// If reauthentication required
|
|
76
|
-
if (result.error?.requiresReauth
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
+
}
|
|
80
87
|
|
|
81
|
-
|
|
88
|
+
const password = await onPasswordRequired();
|
|
82
89
|
|
|
83
|
-
|
|
84
|
-
|
|
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
|
+
}
|
|
85
120
|
}
|
|
86
121
|
|
|
87
|
-
|
|
122
|
+
// Handle Google/Apple reauth
|
|
123
|
+
if (onReauthRequired) {
|
|
88
124
|
if (__DEV__) {
|
|
89
|
-
console.log("[useAccountManagement]
|
|
125
|
+
console.log("[useAccountManagement] Reauth required, calling onReauthRequired callback");
|
|
90
126
|
}
|
|
91
127
|
|
|
92
|
-
const
|
|
93
|
-
autoReauthenticate: false,
|
|
94
|
-
});
|
|
128
|
+
const reauthSuccess = await onReauthRequired();
|
|
95
129
|
|
|
96
130
|
if (__DEV__) {
|
|
97
|
-
console.log("[useAccountManagement]
|
|
131
|
+
console.log("[useAccountManagement] onReauthRequired result:", reauthSuccess);
|
|
98
132
|
}
|
|
99
133
|
|
|
100
|
-
if (
|
|
134
|
+
if (reauthSuccess) {
|
|
101
135
|
if (__DEV__) {
|
|
102
|
-
console.log("[useAccountManagement]
|
|
136
|
+
console.log("[useAccountManagement] Retrying delete after reauth");
|
|
103
137
|
}
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
138
|
|
|
107
|
-
|
|
108
|
-
|
|
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
|
+
}
|
|
109
157
|
}
|
|
110
158
|
}
|
|
111
159
|
}
|
|
@@ -119,7 +167,7 @@ export const useAccountManagement = (
|
|
|
119
167
|
} finally {
|
|
120
168
|
setIsDeletingAccount(false);
|
|
121
169
|
}
|
|
122
|
-
}, [user, onReauthRequired]);
|
|
170
|
+
}, [user, onReauthRequired, onPasswordRequired]);
|
|
123
171
|
|
|
124
172
|
return {
|
|
125
173
|
logout,
|