@umituz/react-native-firebase 1.13.57 → 1.13.59
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/README.md +277 -0
- package/package.json +1 -1
- package/scripts/README.md +513 -0
- package/src/auth/README.md +339 -0
- package/src/auth/domain/README.md +264 -0
- package/src/auth/domain/errors/README.md +291 -0
- package/src/auth/infrastructure/config/README.md +239 -0
- package/src/auth/infrastructure/services/README.md +346 -0
- package/src/auth/infrastructure/stores/README.md +407 -0
- package/src/auth/presentation/hooks/README.md +442 -0
- package/src/domain/README.md +628 -0
- package/src/firestore/README.md +566 -0
- package/src/firestore/domain/README.md +325 -0
- package/src/firestore/domain/constants/README.md +332 -0
- package/src/firestore/domain/entities/README.md +286 -0
- package/src/firestore/domain/errors/README.md +389 -0
- package/src/firestore/infrastructure/config/README.md +239 -0
- package/src/firestore/infrastructure/middleware/README.md +316 -0
- package/src/firestore/infrastructure/repositories/README.md +425 -0
- package/src/firestore/infrastructure/services/README.md +332 -0
- package/src/firestore/types/pagination/README.md +332 -0
- package/src/firestore/utils/README.md +574 -0
- package/src/firestore/utils/dateUtils/README.md +171 -0
- package/src/firestore/utils/document-mapper.helper/README.md +309 -0
- package/src/firestore/utils/pagination.helper/README.md +298 -0
- package/src/firestore/utils/path-resolver/README.md +277 -0
- package/src/firestore/utils/query-builder/README.md +291 -0
- package/src/firestore/utils/quota-error-detector/README.md +355 -0
- package/src/infrastructure/README.md +408 -0
- package/src/infrastructure/config/README.md +262 -0
- package/src/presentation/README.md +556 -0
- package/src/storage/README.md +493 -0
- package/src/storage/deleter/README.md +370 -0
- package/src/storage/types/README.md +313 -0
- package/src/storage/uploader/README.md +409 -0
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
# Admin Scripts
|
|
2
|
+
|
|
3
|
+
Firebase Admin utilities for backend operations, user management, data seeding, cleanup, and maintenance tasks.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
Provides backend/admin tools for Firebase project management using firebase-admin SDK. Use for data operations, user management, cleanup, testing, and maintenance.
|
|
8
|
+
|
|
9
|
+
## For AI Agents
|
|
10
|
+
|
|
11
|
+
### ⚠️ IMPORTANT WARNING
|
|
12
|
+
|
|
13
|
+
**These scripts are for BACKEND/ADMIN use only, NOT for client applications!**
|
|
14
|
+
|
|
15
|
+
### Before Using Admin Scripts
|
|
16
|
+
|
|
17
|
+
1. **UNDERSTAND** these are backend tools, not for client apps
|
|
18
|
+
2. **NEVER** use firebase-admin in client applications (security risk)
|
|
19
|
+
3. **ALWAYS** test in staging before production
|
|
20
|
+
4. **BACKUP** data before destructive operations
|
|
21
|
+
5. **USE** confirmations for dangerous operations
|
|
22
|
+
|
|
23
|
+
### Required Practices
|
|
24
|
+
|
|
25
|
+
1. **Use only in backend/admin contexts** - NEVER in client apps
|
|
26
|
+
2. **Test in staging** before running in production
|
|
27
|
+
3. **Backup data** before destructive operations
|
|
28
|
+
4. **Use confirmations** for dangerous operations
|
|
29
|
+
5. **Monitor progress** for long-running operations
|
|
30
|
+
6. **Handle errors** appropriately and log them
|
|
31
|
+
|
|
32
|
+
### Forbidden Practices
|
|
33
|
+
|
|
34
|
+
## ❌ NEVER
|
|
35
|
+
|
|
36
|
+
- Use firebase-admin in client/frontend applications
|
|
37
|
+
- Run destructive scripts without testing first
|
|
38
|
+
- Skip confirmations for dangerous operations
|
|
39
|
+
- Use admin scripts in browser/React Native
|
|
40
|
+
- Expose admin credentials in client code
|
|
41
|
+
- Delete data without backups
|
|
42
|
+
|
|
43
|
+
## ⚠️ Avoid
|
|
44
|
+
|
|
45
|
+
- Running bulk operations during peak hours
|
|
46
|
+
- Not monitoring operation progress
|
|
47
|
+
- Ignoring errors in batch operations
|
|
48
|
+
- Rate limiting issues (add delays between batches)
|
|
49
|
+
- Not logging operation results
|
|
50
|
+
|
|
51
|
+
## 🏗️ Architecture
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
scripts/
|
|
55
|
+
├── lib/ # Core functionality
|
|
56
|
+
│ ├── admin/ # Firebase admin initialization
|
|
57
|
+
│ ├── auth/ # Authentication admin operations
|
|
58
|
+
│ ├── firestore/ # Firestore admin operations
|
|
59
|
+
│ ├── storage/ # Storage admin operations
|
|
60
|
+
│ ├── credits/ # User credits management
|
|
61
|
+
│ └── utils/ # Utility functions
|
|
62
|
+
└── index.ts # Main entry point and CLI
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## ✅ Required Practices
|
|
66
|
+
|
|
67
|
+
### Security Requirements
|
|
68
|
+
|
|
69
|
+
**Service Account Management:**
|
|
70
|
+
1. Store service account key securely (never in repo)
|
|
71
|
+
2. Use environment variables for credentials
|
|
72
|
+
3. Rotate service account keys regularly
|
|
73
|
+
4. Limit service account permissions (principle of least privilege)
|
|
74
|
+
5. Never commit service account files to version control
|
|
75
|
+
|
|
76
|
+
**Client Application Safety:**
|
|
77
|
+
- **DO NOT** bundle firebase-admin in client builds
|
|
78
|
+
- **DO NOT** expose admin SDK to browser
|
|
79
|
+
- **DO NOT** use admin operations from client code
|
|
80
|
+
- **DO** use client Firebase SDK for app operations
|
|
81
|
+
|
|
82
|
+
### Testing Requirements
|
|
83
|
+
|
|
84
|
+
**Before Production:**
|
|
85
|
+
1. Test all scripts in staging environment
|
|
86
|
+
2. Verify backup/restore procedures
|
|
87
|
+
3. Test with small datasets first
|
|
88
|
+
4. Monitor for errors and edge cases
|
|
89
|
+
5. Document script behavior and results
|
|
90
|
+
|
|
91
|
+
### Operational Safety
|
|
92
|
+
|
|
93
|
+
**For Destructive Operations:**
|
|
94
|
+
1. Always require confirmation (skipConfirmation: false by default)
|
|
95
|
+
2. Show what will be affected before executing
|
|
96
|
+
3. Provide dry-run mode when possible
|
|
97
|
+
4. Log all operations for audit trail
|
|
98
|
+
5. Keep backups until operation verified successful
|
|
99
|
+
|
|
100
|
+
## 🎯 Usage Strategies
|
|
101
|
+
|
|
102
|
+
### For User Management
|
|
103
|
+
|
|
104
|
+
**Strategy:** Use for user cleanup, analytics, and bulk operations.
|
|
105
|
+
|
|
106
|
+
**When to Use:**
|
|
107
|
+
- Cleaning up inactive/anonymous users
|
|
108
|
+
- Generating user analytics reports
|
|
109
|
+
- Bulk user updates (with caution)
|
|
110
|
+
- Debugging user issues
|
|
111
|
+
|
|
112
|
+
**Approach:**
|
|
113
|
+
1. List users to identify targets
|
|
114
|
+
2. Filter by criteria (creation date, activity)
|
|
115
|
+
3. Backup affected user data
|
|
116
|
+
4. Execute operation with confirmation
|
|
117
|
+
5. Verify results and handle errors
|
|
118
|
+
|
|
119
|
+
**Functions:**
|
|
120
|
+
- `listAllUsers()` - List all users
|
|
121
|
+
- `listAnonymousUsers()` - List anonymous users only
|
|
122
|
+
- `deleteUsers(uids)` - Delete specific users
|
|
123
|
+
- `cleanupAnonymousUsers()` - Remove old anonymous users
|
|
124
|
+
- `getAuthUserStats()` - Get user statistics
|
|
125
|
+
|
|
126
|
+
### For Data Seeding
|
|
127
|
+
|
|
128
|
+
**Strategy:** Use for testing, development, and demo data.
|
|
129
|
+
|
|
130
|
+
**When to Use:**
|
|
131
|
+
- Populating development database
|
|
132
|
+
- Creating demo data
|
|
133
|
+
- Testing with realistic datasets
|
|
134
|
+
- Performance testing
|
|
135
|
+
|
|
136
|
+
**Approach:**
|
|
137
|
+
1. Define data structure
|
|
138
|
+
2. Generate or load data
|
|
139
|
+
3. Use batch operations for efficiency
|
|
140
|
+
4. Handle partial failures
|
|
141
|
+
5. Verify seeded data
|
|
142
|
+
|
|
143
|
+
**Functions:**
|
|
144
|
+
- `seedBatch()` - Seed collection with data
|
|
145
|
+
- `seedUserSubcollection()` - Seed user-specific data
|
|
146
|
+
- `deleteCollection()` - Clean up before seeding
|
|
147
|
+
|
|
148
|
+
### For Data Cleanup
|
|
149
|
+
|
|
150
|
+
**Strategy:** Regular maintenance to remove old/unused data.
|
|
151
|
+
|
|
152
|
+
**When to Use:**
|
|
153
|
+
- Removing old anonymous accounts
|
|
154
|
+
- Cleaning up test data
|
|
155
|
+
- Deleting inactive user data
|
|
156
|
+
- Storage cleanup
|
|
157
|
+
|
|
158
|
+
**Approach:**
|
|
159
|
+
1. Identify cleanup criteria (age, activity)
|
|
160
|
+
2. List affected data
|
|
161
|
+
3. Backup if needed
|
|
162
|
+
4. Execute cleanup with confirmations
|
|
163
|
+
5. Verify and log results
|
|
164
|
+
|
|
165
|
+
**Functions:**
|
|
166
|
+
- `deleteCollection()` - Delete entire collection
|
|
167
|
+
- `deleteUserSubcollection()` - Delete user's data
|
|
168
|
+
- `deleteAllData()` - Delete all Firestore data (dangerous!)
|
|
169
|
+
- `deleteAllFiles()` - Delete all Storage files
|
|
170
|
+
- `cleanupAnonymousUsers()` - Remove anonymous users
|
|
171
|
+
|
|
172
|
+
### For Credits Management
|
|
173
|
+
|
|
174
|
+
**Strategy:** Manage user credits and subscriptions.
|
|
175
|
+
|
|
176
|
+
**When to Use:**
|
|
177
|
+
- Adding bonus credits
|
|
178
|
+
- Managing subscriptions
|
|
179
|
+
- Generating credit reports
|
|
180
|
+
- User credit adjustments
|
|
181
|
+
|
|
182
|
+
**Approach:**
|
|
183
|
+
1. Get current user data
|
|
184
|
+
2. Verify operation validity
|
|
185
|
+
3. Execute credit adjustment
|
|
186
|
+
4. Update subscription if needed
|
|
187
|
+
5. Log for audit trail
|
|
188
|
+
|
|
189
|
+
**Functions:**
|
|
190
|
+
- `getUserData()` - Get user with credits
|
|
191
|
+
- `addUserCredits()` - Add credits to user
|
|
192
|
+
- `setUserCredits()` - Set exact credit amount
|
|
193
|
+
- `listUsersWithCredits()` - List all users with credits
|
|
194
|
+
- `getCreditsSummary()` - Get credit statistics
|
|
195
|
+
|
|
196
|
+
### For Analytics and Reporting
|
|
197
|
+
|
|
198
|
+
**Strategy:** Generate insights from Firebase data.
|
|
199
|
+
|
|
200
|
+
**When to Use:**
|
|
201
|
+
- User growth analysis
|
|
202
|
+
- Storage usage reports
|
|
203
|
+
- Credit distribution analysis
|
|
204
|
+
- System health monitoring
|
|
205
|
+
|
|
206
|
+
**Approach:**
|
|
207
|
+
1. Query relevant data
|
|
208
|
+
2. Aggregate and calculate statistics
|
|
209
|
+
3. Format for readability
|
|
210
|
+
4. Export or display results
|
|
211
|
+
|
|
212
|
+
**Functions:**
|
|
213
|
+
- `getAuthUserStats()` - Authentication statistics
|
|
214
|
+
- `getFirestoreUserStats()` - User data statistics
|
|
215
|
+
- `getStorageStats()` - Storage usage statistics
|
|
216
|
+
- `getCreditsSummary()` - Credit distribution
|
|
217
|
+
|
|
218
|
+
## 🔧 Operation Categories
|
|
219
|
+
|
|
220
|
+
### Authentication Admin
|
|
221
|
+
|
|
222
|
+
**User Listing:**
|
|
223
|
+
- `listAllUsers(auth)` - All users with metadata
|
|
224
|
+
- `listAuthenticatedUsers(auth)` - Only non-anonymous users
|
|
225
|
+
- `listAnonymousUsers(auth)` - Only anonymous users
|
|
226
|
+
- `getAuthUserStats(auth)` - User statistics
|
|
227
|
+
|
|
228
|
+
**User Deletion:**
|
|
229
|
+
- `deleteUsers(auth, uids)` - Delete specific users
|
|
230
|
+
- `cleanupAnonymousUsers(auth)` - Delete anonymous users
|
|
231
|
+
- `deleteAllUsers(auth, options?)` - Delete all users (dangerous!)
|
|
232
|
+
|
|
233
|
+
### Firestore Admin
|
|
234
|
+
|
|
235
|
+
**Collection Operations:**
|
|
236
|
+
- `listCollections(firestore)` - List all collections
|
|
237
|
+
- `listUserSubcollections(firestore, uid)` - User's collections
|
|
238
|
+
- `countDocuments(firestore, path)` - Count documents
|
|
239
|
+
- `getFirestoreUserStats(firestore, uid)` - User statistics
|
|
240
|
+
|
|
241
|
+
**Data Deletion:**
|
|
242
|
+
- `deleteCollection(firestore, name)` - Delete collection
|
|
243
|
+
- `deleteUserSubcollection(firestore, uid, name)` - Delete user data
|
|
244
|
+
- `deleteAllData(firestore, options?)` - Delete all (dangerous!)
|
|
245
|
+
|
|
246
|
+
**Data Seeding:**
|
|
247
|
+
- `seedBatch(firestore, collection, data)` - Seed collection
|
|
248
|
+
- `seedUserSubcollection(firestore, uid, name, data)` - Seed user data
|
|
249
|
+
|
|
250
|
+
### Storage Admin
|
|
251
|
+
|
|
252
|
+
**File Operations:**
|
|
253
|
+
- `listFiles(storage, prefix?)` - List files
|
|
254
|
+
- `deleteAllFiles(storage, onProgress?)` - Delete all files
|
|
255
|
+
- `deleteFilesByPrefix(storage, prefix)` - Delete by path
|
|
256
|
+
- `deleteUserFiles(storage, uid)` - Delete user's files
|
|
257
|
+
- `getStorageStats(storage)` - Storage statistics
|
|
258
|
+
|
|
259
|
+
### Credits Management
|
|
260
|
+
|
|
261
|
+
**Credit Operations:**
|
|
262
|
+
- `getUserData(firestore, uid)` - Get user with credits
|
|
263
|
+
- `initializeUserCredits(firestore, uid, data)` - Initialize credits
|
|
264
|
+
- `addUserCredits(firestore, uid, amount)` - Add credits
|
|
265
|
+
- `setUserCredits(firestore, uid, amount)` - Set credits
|
|
266
|
+
- `deleteUserCredits(firestore, uid)` - Delete credits
|
|
267
|
+
|
|
268
|
+
**Reporting:**
|
|
269
|
+
- `listUsersWithCredits(firestore)` - List users with credits
|
|
270
|
+
- `getCreditsSummary(firestore)` - Credit statistics
|
|
271
|
+
- `printUserData(data)` - Pretty print user data
|
|
272
|
+
|
|
273
|
+
## 🤖 AI Agent Instructions
|
|
274
|
+
|
|
275
|
+
### When Creating Admin Scripts
|
|
276
|
+
|
|
277
|
+
1. **Always use firebase-admin**, not client Firebase SDK
|
|
278
|
+
2. **Add confirmations** for destructive operations
|
|
279
|
+
3. **Implement progress tracking** for long operations
|
|
280
|
+
4. **Handle errors** gracefully and log them
|
|
281
|
+
5. **Provide dry-run mode** when possible
|
|
282
|
+
6. **Document script behavior** clearly
|
|
283
|
+
7. **Include examples** in README
|
|
284
|
+
|
|
285
|
+
### When Running Bulk Operations
|
|
286
|
+
|
|
287
|
+
1. Test with small dataset first
|
|
288
|
+
2. Add delays between batches to avoid rate limits
|
|
289
|
+
3. Monitor progress and handle errors
|
|
290
|
+
4. Keep partial failure handling
|
|
291
|
+
5. Log all operations
|
|
292
|
+
6. Verify results after completion
|
|
293
|
+
|
|
294
|
+
### When Adding New Operations
|
|
295
|
+
|
|
296
|
+
1. Check if similar operation exists
|
|
297
|
+
2. Follow existing patterns
|
|
298
|
+
3. Add proper TypeScript types
|
|
299
|
+
4. Include error handling
|
|
300
|
+
5. Document in this README
|
|
301
|
+
6. Add examples for common use cases
|
|
302
|
+
|
|
303
|
+
## 📏 Code Quality Standards
|
|
304
|
+
|
|
305
|
+
### File Size
|
|
306
|
+
|
|
307
|
+
- **Maximum:** 200 lines per file
|
|
308
|
+
- **Strategy:** Split large operations into modules
|
|
309
|
+
- **Current:** Organized by category (auth, firestore, storage, credits)
|
|
310
|
+
|
|
311
|
+
### TypeScript
|
|
312
|
+
|
|
313
|
+
- Use strict mode
|
|
314
|
+
- Define proper types for all functions
|
|
315
|
+
- Export types used by external scripts
|
|
316
|
+
- Never use `any` type
|
|
317
|
+
- Document complex types
|
|
318
|
+
|
|
319
|
+
### Error Handling
|
|
320
|
+
|
|
321
|
+
1. Always try-catch admin operations
|
|
322
|
+
2. Handle Firebase Admin errors
|
|
323
|
+
3. Provide clear error messages
|
|
324
|
+
4. Log errors for debugging
|
|
325
|
+
5. Implement partial failure handling for batches
|
|
326
|
+
|
|
327
|
+
### Naming Conventions
|
|
328
|
+
|
|
329
|
+
- Files: `kebab-case.ts`
|
|
330
|
+
- Functions: `camelCase`
|
|
331
|
+
- Interfaces/Types: `PascalCase`
|
|
332
|
+
- CLI commands: `kebab-case`
|
|
333
|
+
|
|
334
|
+
## 🚨 Common Mistakes to Avoid
|
|
335
|
+
|
|
336
|
+
1. ❌ Using admin SDK in client applications
|
|
337
|
+
- ✅ Only use in backend/admin scripts
|
|
338
|
+
|
|
339
|
+
2. ❌ Skipping confirmation for dangerous operations
|
|
340
|
+
- ✅ Always require confirmation (default behavior)
|
|
341
|
+
|
|
342
|
+
3. ❌ Not testing before production
|
|
343
|
+
- ✅ Test in staging first
|
|
344
|
+
|
|
345
|
+
4. ❌ No backups before destructive operations
|
|
346
|
+
- ✅ Always backup before deleting data
|
|
347
|
+
|
|
348
|
+
5. ❌ Not monitoring long-running operations
|
|
349
|
+
- ✅ Use progress callbacks
|
|
350
|
+
|
|
351
|
+
6. ❌ Ignoring errors in batch operations
|
|
352
|
+
- ✅ Handle and log all errors
|
|
353
|
+
|
|
354
|
+
## 🔐 Security Considerations
|
|
355
|
+
|
|
356
|
+
### Service Account Management
|
|
357
|
+
|
|
358
|
+
**Best Practices:**
|
|
359
|
+
1. Store service account key in secure location
|
|
360
|
+
2. Use environment variables (never hardcode)
|
|
361
|
+
3. Set appropriate file permissions (chmod 600)
|
|
362
|
+
4. Use different service accounts for different environments
|
|
363
|
+
5. Rotate keys regularly
|
|
364
|
+
6. Revoke compromised keys immediately
|
|
365
|
+
|
|
366
|
+
**Environment Variables:**
|
|
367
|
+
Set these environment variables before running scripts:
|
|
368
|
+
- `FIREBASE_SERVICE_ACCOUNT_PATH` - Path to service account JSON file
|
|
369
|
+
- `FIREBASE_PROJECT_ID` - Your Firebase project ID
|
|
370
|
+
- `FIREBASE_STORAGE_BUCKET` - Your Firebase Storage bucket name
|
|
371
|
+
|
|
372
|
+
### Principle of Least Privilege
|
|
373
|
+
|
|
374
|
+
**Service Account Permissions:**
|
|
375
|
+
- Only grant necessary permissions
|
|
376
|
+
- Use custom roles instead of primitive roles
|
|
377
|
+
- Separate service accounts for different tasks
|
|
378
|
+
- Regular audit of permissions
|
|
379
|
+
|
|
380
|
+
**Examples:**
|
|
381
|
+
- Data seeding script: Firestore write only
|
|
382
|
+
- Cleanup script: Firestore delete only
|
|
383
|
+
- Analytics script: Firestore read only
|
|
384
|
+
|
|
385
|
+
### Client Application Safety
|
|
386
|
+
|
|
387
|
+
**CRITICAL Security Examples:**
|
|
388
|
+
|
|
389
|
+
**❌ WRONG - Never do this:**
|
|
390
|
+
- Import firebase-admin in client applications
|
|
391
|
+
- Bundle service account keys in client builds
|
|
392
|
+
- Expose admin SDK to browser/React Native
|
|
393
|
+
- Use admin operations from client code
|
|
394
|
+
|
|
395
|
+
**✅ CORRECT Approach:**
|
|
396
|
+
- Admin scripts: Run in Node.js backend/CLI only
|
|
397
|
+
- Client apps: Use `firebase` client SDK (not firebase-admin)
|
|
398
|
+
- API layer: Create backend API if admin operations needed from client
|
|
399
|
+
- Service accounts: Store securely, never in client code
|
|
400
|
+
|
|
401
|
+
## 📊 Performance Considerations
|
|
402
|
+
|
|
403
|
+
### Batch Operations
|
|
404
|
+
|
|
405
|
+
**Strategy:**
|
|
406
|
+
- Use batch writes (max 500 operations per batch)
|
|
407
|
+
- Add delays between batches (avoid rate limits)
|
|
408
|
+
- Monitor memory usage
|
|
409
|
+
- Process in chunks for large datasets
|
|
410
|
+
|
|
411
|
+
**Example Pattern:**
|
|
412
|
+
1. Split data into chunks of 500
|
|
413
|
+
2. Process each chunk with batch
|
|
414
|
+
3. Wait 1 second between batches
|
|
415
|
+
4. Track progress
|
|
416
|
+
5. Handle partial failures
|
|
417
|
+
|
|
418
|
+
### Rate Limiting
|
|
419
|
+
|
|
420
|
+
**Firebase Limits:**
|
|
421
|
+
- Writes: 1 per document per second
|
|
422
|
+
- Batch writes: 500 operations max
|
|
423
|
+
- List operations: Rate limited after large lists
|
|
424
|
+
|
|
425
|
+
**Mitigation:**
|
|
426
|
+
- Add delays between operations
|
|
427
|
+
- Use batch operations when possible
|
|
428
|
+
- Implement exponential backoff for retries
|
|
429
|
+
- Monitor for rate limit errors
|
|
430
|
+
|
|
431
|
+
## 📚 Related Documentation
|
|
432
|
+
|
|
433
|
+
- [Development Guidelines](../CONTRIBUTING.md)
|
|
434
|
+
- [Firebase Admin SDK](https://firebase.google.com/docs/admin/setup)
|
|
435
|
+
- [Firebase Security](https://firebase.google.com/docs/security)
|
|
436
|
+
|
|
437
|
+
## 🔗 API Reference
|
|
438
|
+
|
|
439
|
+
### Initialization
|
|
440
|
+
|
|
441
|
+
| Function | Description | Usage |
|
|
442
|
+
|----------|-------------|-------|
|
|
443
|
+
| `initFirebaseAdmin(config)` | Initialize Admin SDK | Backend scripts only |
|
|
444
|
+
| `getAuthAdmin(app)` | Get Auth instance | Auth operations |
|
|
445
|
+
| `getFirestoreAdmin(app)` | Get Firestore instance | Database operations |
|
|
446
|
+
| `getStorageAdmin(app)` | Get Storage instance | File operations |
|
|
447
|
+
| `resetFirebaseAdmin()` | Reset instances | Testing only |
|
|
448
|
+
|
|
449
|
+
### Main Export Categories
|
|
450
|
+
|
|
451
|
+
- **Auth Operations** - User management and cleanup
|
|
452
|
+
- **Firestore Operations** - Database operations
|
|
453
|
+
- **Storage Operations** - File management
|
|
454
|
+
- **Credits Management** - User credits and subscriptions
|
|
455
|
+
- **Utilities** - Helper functions
|
|
456
|
+
|
|
457
|
+
## 🎓 Key Concepts
|
|
458
|
+
|
|
459
|
+
### Why Separate Admin SDK?
|
|
460
|
+
|
|
461
|
+
**Client SDK (`firebase`):**
|
|
462
|
+
- For React Native/web applications
|
|
463
|
+
- User-scoped operations
|
|
464
|
+
- Security rules enforced
|
|
465
|
+
- Limited permissions
|
|
466
|
+
|
|
467
|
+
**Admin SDK (`firebase-admin`):**
|
|
468
|
+
- For backend/Node.js only
|
|
469
|
+
- Full access bypassing security rules
|
|
470
|
+
- Service account authentication
|
|
471
|
+
- Complete permissions
|
|
472
|
+
|
|
473
|
+
**Why This Separation?**
|
|
474
|
+
- Security: Prevent privilege escalation
|
|
475
|
+
- Performance: Bypass security rules for bulk ops
|
|
476
|
+
- Safety: Client SDK limits dangerous operations
|
|
477
|
+
- Architecture: Clear separation of concerns
|
|
478
|
+
|
|
479
|
+
### Why Confirmations Required?
|
|
480
|
+
|
|
481
|
+
**Dangerous Operations:**
|
|
482
|
+
- Delete all users
|
|
483
|
+
- Delete all data
|
|
484
|
+
- Delete all files
|
|
485
|
+
- Bulk updates
|
|
486
|
+
|
|
487
|
+
**Confirmation Strategy:**
|
|
488
|
+
1. Default: require explicit confirmation
|
|
489
|
+
2. Show what will be affected
|
|
490
|
+
3. Require `skipConfirmation: true` after understanding
|
|
491
|
+
4. Provide dry-run mode when possible
|
|
492
|
+
5. Log all destructive operations
|
|
493
|
+
|
|
494
|
+
### Why Backup Before Operations?
|
|
495
|
+
|
|
496
|
+
**Data Loss Risks:**
|
|
497
|
+
- Accidental deletion
|
|
498
|
+
- Script bugs
|
|
499
|
+
- Misunderstanding of operation scope
|
|
500
|
+
- Unexpected side effects
|
|
501
|
+
|
|
502
|
+
**Backup Strategy:**
|
|
503
|
+
1. Export Firestore data before bulk operations
|
|
504
|
+
2. Keep backups until operation verified
|
|
505
|
+
3. Test restore procedures
|
|
506
|
+
4. Document backup locations
|
|
507
|
+
5. Set retention policy for backups
|
|
508
|
+
|
|
509
|
+
---
|
|
510
|
+
|
|
511
|
+
**Last Updated:** 2025-01-08
|
|
512
|
+
**Maintainer:** Admin Scripts Team
|
|
513
|
+
**IMPORTANT:** These scripts are for backend/admin use only, never for client applications.
|