@umituz/react-native-firebase 1.13.48 → 1.13.50
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/dist/scripts/cli-handlers.d.ts +27 -0
- package/dist/scripts/cli-handlers.d.ts.map +1 -0
- package/dist/scripts/cli-handlers.js +125 -0
- package/dist/scripts/cli-handlers.js.map +1 -0
- package/dist/scripts/cli-parser.d.ts +25 -0
- package/dist/scripts/cli-parser.d.ts.map +1 -0
- package/dist/scripts/cli-parser.js +101 -0
- package/dist/scripts/cli-parser.js.map +1 -0
- package/dist/scripts/cli.js +20 -155
- package/dist/scripts/cli.js.map +1 -1
- package/dist/scripts/firestore-operations.d.ts +18 -0
- package/dist/scripts/firestore-operations.d.ts.map +1 -0
- package/dist/scripts/firestore-operations.js +88 -0
- package/dist/scripts/firestore-operations.js.map +1 -0
- package/dist/scripts/firestore-queries.d.ts +27 -0
- package/dist/scripts/firestore-queries.d.ts.map +1 -0
- package/dist/scripts/firestore-queries.js +77 -0
- package/dist/scripts/firestore-queries.js.map +1 -0
- package/dist/scripts/firestore-seeding.d.ts +21 -0
- package/dist/scripts/firestore-seeding.d.ts.map +1 -0
- package/dist/scripts/firestore-seeding.js +67 -0
- package/dist/scripts/firestore-seeding.js.map +1 -0
- package/dist/scripts/firestore.d.ts +3 -48
- package/dist/scripts/firestore.d.ts.map +1 -1
- package/dist/scripts/firestore.js +16 -210
- package/dist/scripts/firestore.js.map +1 -1
- package/dist/scripts/user-commands.d.ts +33 -0
- package/dist/scripts/user-commands.d.ts.map +1 -0
- package/dist/scripts/user-commands.js +113 -0
- package/dist/scripts/user-commands.js.map +1 -0
- package/dist/scripts/user-formatters.d.ts +10 -0
- package/dist/scripts/user-formatters.d.ts.map +1 -0
- package/dist/scripts/user-formatters.js +55 -0
- package/dist/scripts/user-formatters.js.map +1 -0
- package/dist/scripts/user-queries.d.ts +42 -0
- package/dist/scripts/user-queries.d.ts.map +1 -0
- package/dist/scripts/user-queries.js +125 -0
- package/dist/scripts/user-queries.js.map +1 -0
- package/dist/scripts/user.d.ts +3 -67
- package/dist/scripts/user.d.ts.map +1 -1
- package/dist/scripts/user.js +15 -272
- package/dist/scripts/user.js.map +1 -1
- package/package.json +1 -1
- package/scripts/cli-handlers.ts +170 -0
- package/scripts/cli-parser.ts +82 -0
- package/scripts/cli.ts +27 -193
- package/scripts/firestore-operations.ts +111 -0
- package/scripts/firestore-queries.ts +97 -0
- package/scripts/firestore-seeding.ts +87 -0
- package/scripts/firestore.ts +20 -275
- package/scripts/user-commands.ts +104 -0
- package/scripts/user-formatters.ts +55 -0
- package/scripts/user-queries.ts +185 -0
- package/scripts/user.ts +19 -326
- package/src/auth/infrastructure/config/FirebaseAuthClient.ts +16 -171
- package/src/auth/infrastructure/services/account-deletion.service.ts +41 -351
- package/src/auth/infrastructure/services/reauthentication.service.ts +47 -207
- package/src/auth/infrastructure/services/reauthentication.types.ts +39 -0
package/scripts/user.ts
CHANGED
|
@@ -3,329 +3,22 @@
|
|
|
3
3
|
* Read and manage user data including credits, subscriptions, transactions
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
includeTransactions = true,
|
|
26
|
-
creditsCollection = "user_credits",
|
|
27
|
-
} = options || {};
|
|
28
|
-
|
|
29
|
-
const result: UserData = {
|
|
30
|
-
userId,
|
|
31
|
-
exists: false,
|
|
32
|
-
profile: null,
|
|
33
|
-
credits: null,
|
|
34
|
-
subscriptions: [],
|
|
35
|
-
transactions: [],
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// Get user profile
|
|
39
|
-
const userDoc = await db.collection("users").doc(userId).get();
|
|
40
|
-
if (userDoc.exists) {
|
|
41
|
-
result.exists = true;
|
|
42
|
-
result.profile = userDoc.data() as Record<string, unknown>;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Get credits from root-level collection
|
|
46
|
-
if (includeCredits) {
|
|
47
|
-
const creditsDoc = await db.collection(creditsCollection).doc(userId).get();
|
|
48
|
-
if (creditsDoc.exists) {
|
|
49
|
-
result.credits = creditsDoc.data() as UserCredits;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Get subscriptions subcollection
|
|
54
|
-
if (includeSubscriptions) {
|
|
55
|
-
const subsSnapshot = await db
|
|
56
|
-
.collection("users")
|
|
57
|
-
.doc(userId)
|
|
58
|
-
.collection("subscriptions")
|
|
59
|
-
.get();
|
|
60
|
-
result.subscriptions = subsSnapshot.docs.map((doc) => ({
|
|
61
|
-
id: doc.id,
|
|
62
|
-
...doc.data(),
|
|
63
|
-
}));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Get transactions subcollection
|
|
67
|
-
if (includeTransactions) {
|
|
68
|
-
const txSnapshot = await db
|
|
69
|
-
.collection("users")
|
|
70
|
-
.doc(userId)
|
|
71
|
-
.collection("transactions")
|
|
72
|
-
.orderBy("createdAt", "desc")
|
|
73
|
-
.limit(50)
|
|
74
|
-
.get();
|
|
75
|
-
result.transactions = txSnapshot.docs.map((doc) => ({
|
|
76
|
-
id: doc.id,
|
|
77
|
-
...doc.data(),
|
|
78
|
-
}));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return result;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Initialize credits for a user
|
|
86
|
-
*/
|
|
87
|
-
export async function initializeUserCredits(
|
|
88
|
-
db: admin.firestore.Firestore,
|
|
89
|
-
userId: string,
|
|
90
|
-
config: CreditsConfig
|
|
91
|
-
): Promise<UserCredits> {
|
|
92
|
-
const { collectionName = "user_credits", textLimit = 0, imageLimit = 0 } = config;
|
|
93
|
-
|
|
94
|
-
const now = admin.firestore.FieldValue.serverTimestamp();
|
|
95
|
-
|
|
96
|
-
const credits: Omit<UserCredits, "createdAt" | "updatedAt"> & {
|
|
97
|
-
createdAt: admin.firestore.FieldValue;
|
|
98
|
-
updatedAt: admin.firestore.FieldValue;
|
|
99
|
-
} = {
|
|
100
|
-
text: textLimit,
|
|
101
|
-
image: imageLimit,
|
|
102
|
-
video: 0,
|
|
103
|
-
audio: 0,
|
|
104
|
-
createdAt: now,
|
|
105
|
-
updatedAt: now,
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
await db.collection(collectionName).doc(userId).set(credits, { merge: true });
|
|
109
|
-
|
|
110
|
-
return {
|
|
111
|
-
text: textLimit,
|
|
112
|
-
image: imageLimit,
|
|
113
|
-
video: 0,
|
|
114
|
-
audio: 0,
|
|
115
|
-
createdAt: new Date(),
|
|
116
|
-
updatedAt: new Date(),
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Add credits to a user
|
|
122
|
-
*/
|
|
123
|
-
export async function addUserCredits(
|
|
124
|
-
db: admin.firestore.Firestore,
|
|
125
|
-
userId: string,
|
|
126
|
-
credits: { text?: number; image?: number; video?: number; audio?: number },
|
|
127
|
-
collectionName = "user_credits"
|
|
128
|
-
): Promise<void> {
|
|
129
|
-
const updates: Record<string, admin.firestore.FieldValue> = {
|
|
130
|
-
updatedAt: admin.firestore.FieldValue.serverTimestamp(),
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
if (credits.text) {
|
|
134
|
-
updates.text = admin.firestore.FieldValue.increment(credits.text);
|
|
135
|
-
}
|
|
136
|
-
if (credits.image) {
|
|
137
|
-
updates.image = admin.firestore.FieldValue.increment(credits.image);
|
|
138
|
-
}
|
|
139
|
-
if (credits.video) {
|
|
140
|
-
updates.video = admin.firestore.FieldValue.increment(credits.video);
|
|
141
|
-
}
|
|
142
|
-
if (credits.audio) {
|
|
143
|
-
updates.audio = admin.firestore.FieldValue.increment(credits.audio);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
await db.collection(collectionName).doc(userId).update(updates);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Set credits for a user (overwrite)
|
|
151
|
-
*/
|
|
152
|
-
export async function setUserCredits(
|
|
153
|
-
db: admin.firestore.Firestore,
|
|
154
|
-
userId: string,
|
|
155
|
-
credits: { text?: number; image?: number; video?: number; audio?: number },
|
|
156
|
-
collectionName = "user_credits"
|
|
157
|
-
): Promise<void> {
|
|
158
|
-
const updates: Record<string, unknown> = {
|
|
159
|
-
updatedAt: admin.firestore.FieldValue.serverTimestamp(),
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
if (credits.text !== undefined) updates.text = credits.text;
|
|
163
|
-
if (credits.image !== undefined) updates.image = credits.image;
|
|
164
|
-
if (credits.video !== undefined) updates.video = credits.video;
|
|
165
|
-
if (credits.audio !== undefined) updates.audio = credits.audio;
|
|
166
|
-
|
|
167
|
-
await db.collection(collectionName).doc(userId).set(updates, { merge: true });
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* List all users with their credit balances
|
|
172
|
-
*/
|
|
173
|
-
export async function listUsersWithCredits(
|
|
174
|
-
db: admin.firestore.Firestore,
|
|
175
|
-
options?: {
|
|
176
|
-
creditsCollection?: string;
|
|
177
|
-
limit?: number;
|
|
178
|
-
onlyWithCredits?: boolean;
|
|
179
|
-
}
|
|
180
|
-
): Promise<
|
|
181
|
-
Array<{
|
|
182
|
-
userId: string;
|
|
183
|
-
displayName?: string;
|
|
184
|
-
email?: string;
|
|
185
|
-
isAnonymous: boolean;
|
|
186
|
-
credits: UserCredits | null;
|
|
187
|
-
}>
|
|
188
|
-
> {
|
|
189
|
-
const { creditsCollection = "user_credits", limit = 100, onlyWithCredits = false } = options || {};
|
|
190
|
-
|
|
191
|
-
const usersSnapshot = await db.collection("users").limit(limit).get();
|
|
192
|
-
const result: Array<{
|
|
193
|
-
userId: string;
|
|
194
|
-
displayName?: string;
|
|
195
|
-
email?: string;
|
|
196
|
-
isAnonymous: boolean;
|
|
197
|
-
credits: UserCredits | null;
|
|
198
|
-
}> = [];
|
|
199
|
-
|
|
200
|
-
for (const userDoc of usersSnapshot.docs) {
|
|
201
|
-
const userData = userDoc.data();
|
|
202
|
-
const creditsDoc = await db.collection(creditsCollection).doc(userDoc.id).get();
|
|
203
|
-
const credits = creditsDoc.exists ? (creditsDoc.data() as UserCredits) : null;
|
|
204
|
-
|
|
205
|
-
if (onlyWithCredits && !credits) continue;
|
|
206
|
-
|
|
207
|
-
result.push({
|
|
208
|
-
userId: userDoc.id,
|
|
209
|
-
displayName: userData.displayName,
|
|
210
|
-
email: userData.email,
|
|
211
|
-
isAnonymous: userData.isAnonymous || false,
|
|
212
|
-
credits,
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
return result;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Delete user credits document
|
|
221
|
-
*/
|
|
222
|
-
export async function deleteUserCredits(
|
|
223
|
-
db: admin.firestore.Firestore,
|
|
224
|
-
userId: string,
|
|
225
|
-
collectionName = "user_credits"
|
|
226
|
-
): Promise<void> {
|
|
227
|
-
await db.collection(collectionName).doc(userId).delete();
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Get credits summary across all users
|
|
232
|
-
*/
|
|
233
|
-
export async function getCreditsSummary(
|
|
234
|
-
db: admin.firestore.Firestore,
|
|
235
|
-
collectionName = "user_credits"
|
|
236
|
-
): Promise<{
|
|
237
|
-
totalUsers: number;
|
|
238
|
-
totalText: number;
|
|
239
|
-
totalImage: number;
|
|
240
|
-
totalVideo: number;
|
|
241
|
-
totalAudio: number;
|
|
242
|
-
usersWithCredits: number;
|
|
243
|
-
usersWithZeroCredits: number;
|
|
244
|
-
}> {
|
|
245
|
-
const snapshot = await db.collection(collectionName).get();
|
|
246
|
-
|
|
247
|
-
let totalText = 0;
|
|
248
|
-
let totalImage = 0;
|
|
249
|
-
let totalVideo = 0;
|
|
250
|
-
let totalAudio = 0;
|
|
251
|
-
let usersWithCredits = 0;
|
|
252
|
-
let usersWithZeroCredits = 0;
|
|
253
|
-
|
|
254
|
-
snapshot.docs.forEach((doc) => {
|
|
255
|
-
const data = doc.data();
|
|
256
|
-
const text = data.text || 0;
|
|
257
|
-
const image = data.image || 0;
|
|
258
|
-
const video = data.video || 0;
|
|
259
|
-
const audio = data.audio || 0;
|
|
260
|
-
|
|
261
|
-
totalText += text;
|
|
262
|
-
totalImage += image;
|
|
263
|
-
totalVideo += video;
|
|
264
|
-
totalAudio += audio;
|
|
265
|
-
|
|
266
|
-
if (text > 0 || image > 0 || video > 0 || audio > 0) {
|
|
267
|
-
usersWithCredits++;
|
|
268
|
-
} else {
|
|
269
|
-
usersWithZeroCredits++;
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
return {
|
|
274
|
-
totalUsers: snapshot.docs.length,
|
|
275
|
-
totalText,
|
|
276
|
-
totalImage,
|
|
277
|
-
totalVideo,
|
|
278
|
-
totalAudio,
|
|
279
|
-
usersWithCredits,
|
|
280
|
-
usersWithZeroCredits,
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* Print user data in formatted way
|
|
286
|
-
*/
|
|
287
|
-
export function printUserData(data: UserData): void {
|
|
288
|
-
console.log("\n" + "═".repeat(60));
|
|
289
|
-
console.log(`👤 USER: ${data.userId}`);
|
|
290
|
-
console.log("═".repeat(60));
|
|
291
|
-
|
|
292
|
-
console.log("\n📋 PROFILE:");
|
|
293
|
-
if (data.profile) {
|
|
294
|
-
console.log(JSON.stringify(data.profile, null, 2));
|
|
295
|
-
} else {
|
|
296
|
-
console.log(" ❌ Not found");
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
console.log("\n💰 CREDITS:");
|
|
300
|
-
if (data.credits) {
|
|
301
|
-
console.log(` Text: ${data.credits.text || 0}`);
|
|
302
|
-
console.log(` Image: ${data.credits.image || 0}`);
|
|
303
|
-
console.log(` Video: ${data.credits.video || 0}`);
|
|
304
|
-
console.log(` Audio: ${data.credits.audio || 0}`);
|
|
305
|
-
} else {
|
|
306
|
-
console.log(" ❌ Not found");
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
console.log("\n🔔 SUBSCRIPTIONS:");
|
|
310
|
-
if (data.subscriptions.length > 0) {
|
|
311
|
-
data.subscriptions.forEach((sub) => {
|
|
312
|
-
console.log(` - ${sub.id}: ${JSON.stringify(sub)}`);
|
|
313
|
-
});
|
|
314
|
-
} else {
|
|
315
|
-
console.log(" ❌ None");
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
console.log("\n🧾 TRANSACTIONS:");
|
|
319
|
-
if (data.transactions.length > 0) {
|
|
320
|
-
data.transactions.slice(0, 5).forEach((tx) => {
|
|
321
|
-
console.log(` - ${tx.id}: ${JSON.stringify(tx)}`);
|
|
322
|
-
});
|
|
323
|
-
if (data.transactions.length > 5) {
|
|
324
|
-
console.log(` ... and ${data.transactions.length - 5} more`);
|
|
325
|
-
}
|
|
326
|
-
} else {
|
|
327
|
-
console.log(" ❌ None");
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
console.log("\n" + "═".repeat(60) + "\n");
|
|
331
|
-
}
|
|
6
|
+
// Query functions
|
|
7
|
+
export {
|
|
8
|
+
getUserData,
|
|
9
|
+
listUsersWithCredits,
|
|
10
|
+
getCreditsSummary,
|
|
11
|
+
} from "./user-queries";
|
|
12
|
+
|
|
13
|
+
// Command functions
|
|
14
|
+
export {
|
|
15
|
+
initializeUserCredits,
|
|
16
|
+
addUserCredits,
|
|
17
|
+
setUserCredits,
|
|
18
|
+
deleteUserCredits,
|
|
19
|
+
} from "./user-commands";
|
|
20
|
+
|
|
21
|
+
// Formatter functions
|
|
22
|
+
export {
|
|
23
|
+
printUserData,
|
|
24
|
+
} from "./user-formatters";
|
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Firebase Auth Client - Infrastructure Layer
|
|
3
|
-
*
|
|
4
|
-
* Domain-Driven Design: Infrastructure implementation of Firebase Auth client
|
|
5
|
-
* Singleton pattern for managing Firebase Auth instance
|
|
6
|
-
*
|
|
7
|
-
* IMPORTANT: This package requires Firebase App to be initialized first.
|
|
8
|
-
* Use @umituz/react-native-firebase to initialize Firebase App.
|
|
9
|
-
*
|
|
10
|
-
* SOLID Principles:
|
|
11
|
-
* - Single Responsibility: Only manages Auth initialization
|
|
12
|
-
* - Open/Closed: Extensible through configuration, closed for modification
|
|
13
|
-
* - Dependency Inversion: Depends on Firebase App from @umituz/react-native-firebase
|
|
14
3
|
*/
|
|
15
4
|
|
|
16
5
|
import type { Auth } from 'firebase/auth';
|
|
@@ -20,190 +9,46 @@ import type { FirebaseAuthConfig } from '../../domain/value-objects/FirebaseAuth
|
|
|
20
9
|
|
|
21
10
|
declare const __DEV__: boolean;
|
|
22
11
|
|
|
23
|
-
/**
|
|
24
|
-
* Firebase Auth Client Singleton
|
|
25
|
-
* Manages Firebase Auth initialization
|
|
26
|
-
*/
|
|
27
12
|
class FirebaseAuthClientSingleton {
|
|
28
13
|
private static instance: FirebaseAuthClientSingleton | null = null;
|
|
29
14
|
private auth: Auth | null = null;
|
|
30
15
|
private initializationError: string | null = null;
|
|
31
16
|
|
|
32
|
-
private constructor() {
|
|
33
|
-
// Private constructor to enforce singleton pattern
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Get singleton instance
|
|
38
|
-
*/
|
|
39
17
|
static getInstance(): FirebaseAuthClientSingleton {
|
|
40
|
-
if (!
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
return FirebaseAuthClientSingleton.instance;
|
|
18
|
+
if (!this.instance) this.instance = new FirebaseAuthClientSingleton();
|
|
19
|
+
return this.instance;
|
|
44
20
|
}
|
|
45
21
|
|
|
46
|
-
/**
|
|
47
|
-
* Initialize Firebase Auth
|
|
48
|
-
* Requires Firebase App to be initialized first via @umituz/react-native-firebase
|
|
49
|
-
*
|
|
50
|
-
* @param config - Optional Firebase Auth configuration
|
|
51
|
-
* @returns Firebase Auth instance or null if initialization fails
|
|
52
|
-
*/
|
|
53
22
|
initialize(config?: FirebaseAuthConfig): Auth | null {
|
|
54
|
-
|
|
55
|
-
if (this.
|
|
56
|
-
if (__DEV__) {
|
|
57
|
-
console.log('[FirebaseAuth] Already initialized, returning existing instance');
|
|
58
|
-
}
|
|
59
|
-
return this.auth;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Don't retry if initialization already failed
|
|
63
|
-
if (this.initializationError) {
|
|
64
|
-
if (__DEV__) {
|
|
65
|
-
console.warn('[FirebaseAuth] Previous initialization failed:', this.initializationError);
|
|
66
|
-
}
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
23
|
+
if (this.auth) return this.auth;
|
|
24
|
+
if (this.initializationError) return null;
|
|
69
25
|
|
|
70
26
|
try {
|
|
71
|
-
// Get Firebase App instance (must be initialized first)
|
|
72
27
|
const app = getFirebaseApp();
|
|
73
|
-
|
|
74
|
-
// Return null if Firebase App is not available (offline mode)
|
|
75
|
-
if (!app) {
|
|
76
|
-
if (__DEV__) {
|
|
77
|
-
console.log('[FirebaseAuth] Firebase App not available - skipping Auth initialization');
|
|
78
|
-
}
|
|
79
|
-
// Don't set initializationError - this is normal offline mode
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (__DEV__) {
|
|
84
|
-
console.log('[FirebaseAuth] Initializing Firebase Auth...');
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Initialize Auth
|
|
28
|
+
if (!app) return null;
|
|
88
29
|
this.auth = FirebaseAuthInitializer.initialize(app, config);
|
|
89
|
-
|
|
90
|
-
if (this.auth) {
|
|
91
|
-
if (__DEV__) {
|
|
92
|
-
console.log('[FirebaseAuth] ✅ Successfully initialized');
|
|
93
|
-
}
|
|
94
|
-
} else {
|
|
95
|
-
if (__DEV__) {
|
|
96
|
-
console.warn('[FirebaseAuth] ⚠️ Initialization returned null');
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
30
|
return this.auth;
|
|
101
|
-
} catch (error) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (__DEV__) {
|
|
105
|
-
console.error('[FirebaseAuth] ❌ Initialization error:', errorMessage);
|
|
106
|
-
}
|
|
107
|
-
if (!errorMessage.includes('not initialized') && !errorMessage.includes('not available')) {
|
|
108
|
-
this.initializationError = errorMessage;
|
|
109
|
-
}
|
|
31
|
+
} catch (error: any) {
|
|
32
|
+
if (__DEV__) console.error('[FirebaseAuth] Init error:', error.message);
|
|
33
|
+
this.initializationError = error.message;
|
|
110
34
|
return null;
|
|
111
35
|
}
|
|
112
36
|
}
|
|
113
37
|
|
|
114
|
-
/**
|
|
115
|
-
* Get the Firebase Auth instance
|
|
116
|
-
* Auto-initializes if Firebase App is available
|
|
117
|
-
* Returns null if config is not available (offline mode - no error)
|
|
118
|
-
* @returns Firebase Auth instance or null if not initialized
|
|
119
|
-
*/
|
|
120
38
|
getAuth(): Auth | null {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
try {
|
|
124
|
-
// Try to get Firebase App (will auto-initialize if config is available)
|
|
125
|
-
const app = getFirebaseApp();
|
|
126
|
-
if (app) {
|
|
127
|
-
this.initialize();
|
|
128
|
-
}
|
|
129
|
-
} catch {
|
|
130
|
-
// Firebase App not available, return null (offline mode)
|
|
131
|
-
return null;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// Return null if not initialized (offline mode - no error)
|
|
136
|
-
return this.auth || null;
|
|
39
|
+
if (!this.auth && !this.initializationError && getFirebaseApp()) this.initialize();
|
|
40
|
+
return this.auth;
|
|
137
41
|
}
|
|
138
42
|
|
|
139
|
-
|
|
140
|
-
* Check if Auth is initialized
|
|
141
|
-
*/
|
|
142
|
-
isInitialized(): boolean {
|
|
143
|
-
return this.auth !== null;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Get initialization error if any
|
|
148
|
-
*/
|
|
149
|
-
getInitializationError(): string | null {
|
|
150
|
-
return this.initializationError;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Reset the Auth client instance
|
|
155
|
-
* Useful for testing
|
|
156
|
-
*/
|
|
157
|
-
reset(): void {
|
|
158
|
-
this.auth = null;
|
|
159
|
-
this.initializationError = null;
|
|
160
|
-
}
|
|
43
|
+
reset(): void { this.auth = null; this.initializationError = null; }
|
|
161
44
|
}
|
|
162
45
|
|
|
163
|
-
/**
|
|
164
|
-
* Singleton instance
|
|
165
|
-
*/
|
|
166
46
|
export const firebaseAuthClient = FirebaseAuthClientSingleton.getInstance();
|
|
47
|
+
export const initializeFirebaseAuth = (c?: FirebaseAuthConfig) => firebaseAuthClient.initialize(c);
|
|
48
|
+
export const getFirebaseAuth = () => firebaseAuthClient.getAuth();
|
|
49
|
+
export const isFirebaseAuthInitialized = () => firebaseAuthClient.getAuth() !== null;
|
|
50
|
+
export const getFirebaseAuthInitializationError = () => firebaseAuthClient.initialize() ? null : "Not initialized";
|
|
51
|
+
export const resetFirebaseAuthClient = () => firebaseAuthClient.reset();
|
|
167
52
|
|
|
168
|
-
export function initializeFirebaseAuth(
|
|
169
|
-
config?: FirebaseAuthConfig
|
|
170
|
-
): Auth | null {
|
|
171
|
-
return firebaseAuthClient.initialize(config);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Get Firebase Auth instance
|
|
176
|
-
* Auto-initializes if Firebase App is available
|
|
177
|
-
* Returns null if config is not available (offline mode - no error)
|
|
178
|
-
* @returns Firebase Auth instance or null if not initialized
|
|
179
|
-
*/
|
|
180
|
-
export function getFirebaseAuth(): Auth | null {
|
|
181
|
-
return firebaseAuthClient.getAuth();
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Check if Firebase Auth is initialized
|
|
186
|
-
*/
|
|
187
|
-
export function isFirebaseAuthInitialized(): boolean {
|
|
188
|
-
return firebaseAuthClient.isInitialized();
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Get initialization error if any
|
|
193
|
-
*/
|
|
194
|
-
export function getFirebaseAuthInitializationError(): string | null {
|
|
195
|
-
return firebaseAuthClient.getInitializationError();
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Reset Firebase Auth client instance
|
|
200
|
-
* Useful for testing
|
|
201
|
-
*/
|
|
202
|
-
export function resetFirebaseAuthClient(): void {
|
|
203
|
-
firebaseAuthClient.reset();
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// Export types
|
|
207
53
|
export type { Auth } from 'firebase/auth';
|
|
208
54
|
export type { FirebaseAuthConfig } from '../../domain/value-objects/FirebaseAuthConfig';
|
|
209
|
-
|