I’m implementing Firebase Auth in a mobile health tracking app to allow Google/Apple login alongside existing email/password, plus anonymous usage for basic features.
Context: The app helps users track cycles, health symptoms, and provides community features. Since it deals with sensitive health data, privacy and data retention are critical.
Current Setup:
- Frontend: React Native (mobile)
- Backend: NestJS + MongoDB (Mongoose)
- Auth: Email/password with mandatory email verification
- Adding: Firebase Auth for Google/Apple OAuth + anonymous auth
- Goal: Anonymous users can use basic features, premium features require authentication
Architecture:
// MongoDB stores all user data
// Firebase Auth provides UID
const user = {
firebaseUid: "anonymous_abc123",
cycleData: [...],
notes: [...],
settings: {...}
};
Concern: If a user uses the app anonymously for weeks and then deletes it, their data remains in MongoDB indefinitely. Over time, this creates unnecessary data growth.
Question: How can I detect and clean up anonymous user data in MongoDB when:
- An anonymous user deletes the app from device
- Anonymous data is no longer associated with an active user