@umituz/react-native-firebase 1.13.23 → 1.13.25
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-firebase",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.25",
|
|
4
4
|
"description": "Unified Firebase package for React Native apps - Auth and Firestore services using Firebase JS SDK (no native modules).",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
package/src/auth/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { getFirebaseAuth } from "../config/FirebaseAuthClient";
|
|
|
10
10
|
import {
|
|
11
11
|
getUserAuthProvider,
|
|
12
12
|
reauthenticateWithApple,
|
|
13
|
+
reauthenticateWithPassword,
|
|
13
14
|
} from "./reauthentication.service";
|
|
14
15
|
|
|
15
16
|
export interface AccountDeletionResult {
|
|
@@ -27,6 +28,11 @@ export interface AccountDeletionOptions {
|
|
|
27
28
|
* This must be provided by the calling code after prompting user for Google sign-in
|
|
28
29
|
*/
|
|
29
30
|
googleIdToken?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Password for reauthentication (required if user signed in with email/password)
|
|
33
|
+
* This must be provided by the calling code after prompting user for password
|
|
34
|
+
*/
|
|
35
|
+
password?: string;
|
|
30
36
|
/**
|
|
31
37
|
* If true, will attempt to reauthenticate with Apple automatically
|
|
32
38
|
* (shows Apple sign-in prompt to user)
|
|
@@ -42,9 +48,16 @@ export interface AccountDeletionOptions {
|
|
|
42
48
|
export async function deleteCurrentUser(
|
|
43
49
|
options: AccountDeletionOptions = { autoReauthenticate: true }
|
|
44
50
|
): Promise<AccountDeletionResult> {
|
|
51
|
+
if (__DEV__) {
|
|
52
|
+
console.log("[deleteCurrentUser] Starting with options:", options);
|
|
53
|
+
}
|
|
54
|
+
|
|
45
55
|
const auth = getFirebaseAuth();
|
|
46
56
|
|
|
47
57
|
if (!auth) {
|
|
58
|
+
if (__DEV__) {
|
|
59
|
+
console.log("[deleteCurrentUser] ❌ Firebase Auth not initialized");
|
|
60
|
+
}
|
|
48
61
|
return {
|
|
49
62
|
success: false,
|
|
50
63
|
error: {
|
|
@@ -58,6 +71,9 @@ export async function deleteCurrentUser(
|
|
|
58
71
|
const user = auth.currentUser;
|
|
59
72
|
|
|
60
73
|
if (!user) {
|
|
74
|
+
if (__DEV__) {
|
|
75
|
+
console.log("[deleteCurrentUser] ❌ No user signed in");
|
|
76
|
+
}
|
|
61
77
|
return {
|
|
62
78
|
success: false,
|
|
63
79
|
error: {
|
|
@@ -69,6 +85,9 @@ export async function deleteCurrentUser(
|
|
|
69
85
|
}
|
|
70
86
|
|
|
71
87
|
if (user.isAnonymous) {
|
|
88
|
+
if (__DEV__) {
|
|
89
|
+
console.log("[deleteCurrentUser] ❌ Cannot delete anonymous user");
|
|
90
|
+
}
|
|
72
91
|
return {
|
|
73
92
|
success: false,
|
|
74
93
|
error: {
|
|
@@ -79,18 +98,47 @@ export async function deleteCurrentUser(
|
|
|
79
98
|
};
|
|
80
99
|
}
|
|
81
100
|
|
|
101
|
+
if (__DEV__) {
|
|
102
|
+
const provider = getUserAuthProvider(user);
|
|
103
|
+
console.log("[deleteCurrentUser] User info:", {
|
|
104
|
+
uid: user.uid,
|
|
105
|
+
provider,
|
|
106
|
+
providerData: user.providerData?.map(p => p.providerId),
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
82
110
|
// First attempt to delete
|
|
83
111
|
try {
|
|
112
|
+
if (__DEV__) {
|
|
113
|
+
console.log("[deleteCurrentUser] Attempting to delete user...");
|
|
114
|
+
}
|
|
84
115
|
await deleteUser(user);
|
|
116
|
+
if (__DEV__) {
|
|
117
|
+
console.log("[deleteCurrentUser] ✅ User deleted successfully");
|
|
118
|
+
}
|
|
85
119
|
return { success: true };
|
|
86
120
|
} catch (error) {
|
|
87
121
|
const firebaseError = error as { code?: string; message?: string };
|
|
88
122
|
const requiresReauth = firebaseError.code === "auth/requires-recent-login";
|
|
89
123
|
|
|
124
|
+
if (__DEV__) {
|
|
125
|
+
console.log("[deleteCurrentUser] First delete attempt failed:", {
|
|
126
|
+
code: firebaseError.code,
|
|
127
|
+
message: firebaseError.message,
|
|
128
|
+
requiresReauth,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
90
132
|
// If reauthentication is required and autoReauthenticate is enabled
|
|
91
133
|
if (requiresReauth && options.autoReauthenticate) {
|
|
134
|
+
if (__DEV__) {
|
|
135
|
+
console.log("[deleteCurrentUser] Attempting auto-reauthentication...");
|
|
136
|
+
}
|
|
92
137
|
const reauthResult = await attemptReauthenticationAndDelete(user, options);
|
|
93
138
|
if (reauthResult) {
|
|
139
|
+
if (__DEV__) {
|
|
140
|
+
console.log("[deleteCurrentUser] Auto-reauth result:", reauthResult);
|
|
141
|
+
}
|
|
94
142
|
return reauthResult;
|
|
95
143
|
}
|
|
96
144
|
}
|
|
@@ -117,17 +165,38 @@ async function attemptReauthenticationAndDelete(
|
|
|
117
165
|
): Promise<AccountDeletionResult | null> {
|
|
118
166
|
const provider = getUserAuthProvider(user);
|
|
119
167
|
|
|
168
|
+
if (__DEV__) {
|
|
169
|
+
console.log("[attemptReauthenticationAndDelete] Provider:", provider);
|
|
170
|
+
}
|
|
171
|
+
|
|
120
172
|
// Handle Apple reauthentication
|
|
121
173
|
if (provider === "apple.com") {
|
|
174
|
+
if (__DEV__) {
|
|
175
|
+
console.log("[attemptReauthenticationAndDelete] Attempting Apple reauthentication...");
|
|
176
|
+
}
|
|
177
|
+
|
|
122
178
|
const reauthResult = await reauthenticateWithApple(user);
|
|
123
179
|
|
|
180
|
+
if (__DEV__) {
|
|
181
|
+
console.log("[attemptReauthenticationAndDelete] Apple reauth result:", reauthResult);
|
|
182
|
+
}
|
|
183
|
+
|
|
124
184
|
if (reauthResult.success) {
|
|
125
185
|
// Retry deletion after successful reauthentication
|
|
126
186
|
try {
|
|
187
|
+
if (__DEV__) {
|
|
188
|
+
console.log("[attemptReauthenticationAndDelete] Deleting user after Apple reauth...");
|
|
189
|
+
}
|
|
127
190
|
await deleteUser(user);
|
|
191
|
+
if (__DEV__) {
|
|
192
|
+
console.log("[attemptReauthenticationAndDelete] ✅ User deleted after Apple reauth");
|
|
193
|
+
}
|
|
128
194
|
return { success: true };
|
|
129
195
|
} catch (deleteError) {
|
|
130
196
|
const firebaseError = deleteError as { code?: string; message?: string };
|
|
197
|
+
if (__DEV__) {
|
|
198
|
+
console.log("[attemptReauthenticationAndDelete] ❌ Delete failed after Apple reauth:", firebaseError);
|
|
199
|
+
}
|
|
131
200
|
return {
|
|
132
201
|
success: false,
|
|
133
202
|
error: {
|
|
@@ -139,6 +208,9 @@ async function attemptReauthenticationAndDelete(
|
|
|
139
208
|
}
|
|
140
209
|
} else {
|
|
141
210
|
// Reauthentication failed
|
|
211
|
+
if (__DEV__) {
|
|
212
|
+
console.log("[attemptReauthenticationAndDelete] ❌ Apple reauth failed");
|
|
213
|
+
}
|
|
142
214
|
return {
|
|
143
215
|
success: false,
|
|
144
216
|
error: {
|
|
@@ -196,6 +268,76 @@ async function attemptReauthenticationAndDelete(
|
|
|
196
268
|
}
|
|
197
269
|
}
|
|
198
270
|
|
|
271
|
+
// Handle Password reauthentication (requires password from caller)
|
|
272
|
+
if (provider === "password") {
|
|
273
|
+
if (__DEV__) {
|
|
274
|
+
console.log("[attemptReauthenticationAndDelete] Password provider detected");
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// For password, we need the caller to provide the password
|
|
278
|
+
if (!options.password) {
|
|
279
|
+
if (__DEV__) {
|
|
280
|
+
console.log("[attemptReauthenticationAndDelete] No password provided, requesting reauth");
|
|
281
|
+
}
|
|
282
|
+
return {
|
|
283
|
+
success: false,
|
|
284
|
+
error: {
|
|
285
|
+
code: "auth/password-reauth-required",
|
|
286
|
+
message: "Please enter your password to delete your account",
|
|
287
|
+
requiresReauth: true,
|
|
288
|
+
},
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (__DEV__) {
|
|
293
|
+
console.log("[attemptReauthenticationAndDelete] Attempting password reauthentication...");
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const reauthResult = await reauthenticateWithPassword(user, options.password);
|
|
297
|
+
|
|
298
|
+
if (__DEV__) {
|
|
299
|
+
console.log("[attemptReauthenticationAndDelete] Password reauth result:", reauthResult);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (reauthResult.success) {
|
|
303
|
+
try {
|
|
304
|
+
if (__DEV__) {
|
|
305
|
+
console.log("[attemptReauthenticationAndDelete] Deleting user after password reauth...");
|
|
306
|
+
}
|
|
307
|
+
await deleteUser(user);
|
|
308
|
+
if (__DEV__) {
|
|
309
|
+
console.log("[attemptReauthenticationAndDelete] ✅ User deleted after password reauth");
|
|
310
|
+
}
|
|
311
|
+
return { success: true };
|
|
312
|
+
} catch (deleteError) {
|
|
313
|
+
const firebaseError = deleteError as { code?: string; message?: string };
|
|
314
|
+
if (__DEV__) {
|
|
315
|
+
console.log("[attemptReauthenticationAndDelete] ❌ Delete failed after password reauth:", firebaseError);
|
|
316
|
+
}
|
|
317
|
+
return {
|
|
318
|
+
success: false,
|
|
319
|
+
error: {
|
|
320
|
+
code: firebaseError.code || "auth/deletion-failed-after-reauth",
|
|
321
|
+
message: firebaseError.message || "Failed to delete account after reauthentication",
|
|
322
|
+
requiresReauth: false,
|
|
323
|
+
},
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
} else {
|
|
327
|
+
if (__DEV__) {
|
|
328
|
+
console.log("[attemptReauthenticationAndDelete] ❌ Password reauth failed");
|
|
329
|
+
}
|
|
330
|
+
return {
|
|
331
|
+
success: false,
|
|
332
|
+
error: {
|
|
333
|
+
code: reauthResult.error?.code || "auth/reauthentication-failed",
|
|
334
|
+
message: reauthResult.error?.message || "Password reauthentication failed",
|
|
335
|
+
requiresReauth: true,
|
|
336
|
+
},
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
199
341
|
// For other providers, return null to use the default error handling
|
|
200
342
|
return null;
|
|
201
343
|
}
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
reauthenticateWithCredential,
|
|
10
10
|
GoogleAuthProvider,
|
|
11
11
|
OAuthProvider,
|
|
12
|
+
EmailAuthProvider,
|
|
12
13
|
type User,
|
|
13
14
|
type AuthCredential,
|
|
14
15
|
} from "firebase/auth";
|
|
@@ -83,6 +84,39 @@ export async function reauthenticateWithGoogle(
|
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Reauthenticate with Email/Password
|
|
89
|
+
*/
|
|
90
|
+
export async function reauthenticateWithPassword(
|
|
91
|
+
user: User,
|
|
92
|
+
password: string
|
|
93
|
+
): Promise<ReauthenticationResult> {
|
|
94
|
+
try {
|
|
95
|
+
if (!user.email) {
|
|
96
|
+
return {
|
|
97
|
+
success: false,
|
|
98
|
+
error: {
|
|
99
|
+
code: "auth/no-email",
|
|
100
|
+
message: "User has no email address",
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const credential = EmailAuthProvider.credential(user.email, password);
|
|
106
|
+
await reauthenticateWithCredential(user, credential);
|
|
107
|
+
return { success: true };
|
|
108
|
+
} catch (error) {
|
|
109
|
+
const firebaseError = error as { code?: string; message?: string };
|
|
110
|
+
return {
|
|
111
|
+
success: false,
|
|
112
|
+
error: {
|
|
113
|
+
code: firebaseError.code || "auth/reauthentication-failed",
|
|
114
|
+
message: firebaseError.message || "Password reauthentication failed",
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
86
120
|
/**
|
|
87
121
|
* Generate a random nonce for Apple Sign-In security
|
|
88
122
|
*/
|