Repository navigation
Closed
Description
Problem
Currently, when anonymous users sign in to create an account, they lose all their existing spending data. This is a critical user experience issue that could frustrate users and cause data loss.
Current Behavior
- User tracks spending without signing in (data stored with anonymous user_id)
- User signs in to access data on other devices
- User gets new authenticated user_id
- All previous spending data is lost (remains tied to old anonymous user_id)
- User starts with empty spending history
What Currently Works
- ✅ Currency preference migration (localStorage → database)
- ✅ User can access account on other devices
- ✅ Robust authentication system
What's Missing
- ❌ Spending data migration from anonymous to authenticated user_id
- ❌ Warning users about potential data loss before authentication
Technical Details
Root Cause:
- Spending entries are stored with
user_idinspending_entriestable - Anonymous users get one
user_id, authenticated users get a differentuser_id - No migration logic exists to transfer spending data between user IDs
Files Involved:
src/composables/useAuth.ts- Authentication state managementsrc/composables/useSpendingStore.ts- Spending data storagesrc/composables/useUserPreferences.ts- Has working migration example
Reference Implementation:
The useUserPreferences.ts already has a working migrateGuestPreferences() function that migrates currency settings. This can serve as a template for spending data migration.
Proposed Solution
Implement a migrateSpendingData() function that:
- Capture anonymous user_id before authentication transition
- Transfer spending entries from anonymous user_id to authenticated user_id
- Verify data integrity during migration
- Handle migration failures gracefully
- Clean up orphaned data after successful migration
Implementation Approach
// In useSpendingStore.ts
const migrateAnonymousSpendingData = async (oldUserId: string, newUserId: string) => {
try {
// Update all spending_entries from old user_id to new user_id
const { error } = await supabase
.from('spending_entries')
.update({ user_id: newUserId })
.eq('user_id', oldUserId)
if (error) throw error
// Reload entries for new user
await loadEntries()
} catch (error) {
console.error('Failed to migrate spending data:', error)
// Handle migration failure
}
}Acceptance Criteria
- Anonymous users can sign in without losing spending data
- All spending entries are transferred to authenticated account
- Migration handles errors gracefully
- Data integrity is maintained during migration
- User sees seamless transition (no data loss)
- Migration works across all authentication methods (email, Google, Facebook)
Priority
High Priority - This is a critical user experience issue that could cause significant user frustration and data loss.
Related
- Part of the authentication system completion
- Mentioned in CLAUDE.md as remaining implementation work: "Data Migration - Moving guest data to authenticated accounts"
Metadata
Metadata
Assignees
Labels
No labels
Activity
feat: implement spending data migration for anonymous to authenticate…
Release: Major authentication and user management features (#50)
Release v1.3.0: Facebook OAuth UI removal and version bump (#51)