8000 Backend User Preferences Integration · Issue #42 · laminko/SpendCheck · GitHub
[go: up one dir, main page]

Skip to content

Backend User Preferences Integration #42

Closed

Description

@laminko

Feature: Backend User Preferences Integration

Overview

Update existing composables and create new infrastructure to handle authenticated vs guest user states for preferences, ensuring seamless data management across user authentication states.

Parent Issue

Part of #37 - Add Settings Page with Authentication and User Management

Current Status

  • ✅ Authentication system fully implemented
  • ✅ Composables exist for preferences (currency, categories)
  • ❌ Composables don't differentiate between guest vs authenticated users
  • ❌ No data migration system for guest → authenticated transition
  • ❌ No unified preferences management system

Requirements

Composable Updates

  • Update useCurrency.ts to handle auth vs guest states
  • Update useCategoryStore.ts for user-specific categories
  • Create useUserPreferences.ts as central preferences manager
  • Implement preference loading priority system
  • Add preference synchronization capabilities

Authentication State Handling

  • Detect authentication state changes
  • Trigger preference loading on sign-in
  • Handle preference cleanup on sign-out
  • Manage preference conflicts during auth transitions

Data Migration System

  • Create guest → authenticated user data migration
  • Handle preference conflicts (guest vs server data)
  • Implement user choice for conflicting preferences
  • Ensure data integrity during migration

Preference Management

  • Centralized preference loading/saving
  • Cache management for performance
  • Offline/online state handling
  • Preference validation and error handling

Technical Architecture

New Composable: useUserPreferences.ts

interface UserPreferences {
  currency: CurrencyConfig
  categories: Category[]
  // Future: theme, notifications, etc.
}

// Functions:
- loadUserPreferences()
- saveUserPreferences()
- migrateGuestPreferences()
- handleAuthStateChange()

Updated Composables

  • useCurrency.ts: Integrate with user preferences system
  • useCategoryStore.ts: Support user-specific categories
  • useAuth.ts: Trigger preference loading on auth changes

Data Flow

App Startup → Check Auth State → Load Preferences
Guest → localStorage
Authenticated → Database + localStorage cache

Auth State Change → Migrate Data → Update UI

Implementation Details

Preference Loading Priority

  1. Database (authenticated users)
  2. localStorage cache (performance optimization)
  3. Default values (fallback)

Migration Strategy

Sign In:
  1. Load current localStorage preferences
  2. Load database preferences
  3. Merge/conflict resolution
  4. Save merged preferences to database
  5. Update UI state

Sign Out:
  1. Clear user-specific data
  2. Reset to default/guest preferences
  3. Clean up cache

Acceptance Criteria

  • Composables properly handle authenticated vs guest users
  • Preferences load automatically on authentication changes
  • Guest preferences migrate smoothly to authenticated accounts
  • No data loss during authentication transitions
  • Performance optimized with proper caching
  • Robust error handling for all preference operations
  • Clean separation between guest and user data

Technical Considerations

  • Implement proper TypeScript types for all preference data
  • Handle race conditions during rapid auth state changes
  • Ensure proper cleanup to prevent memory leaks
  • Consider preference versioning for future schema changes
  • Implement comprehensive error recovery mechanisms

Priority

Medium - Foundation for other preference features

Dependencies

  • Database schema for user_preferences table
  • Currency preference storage implementation
  • Category management system

Related Issues

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

Activity

  1. laminko commented on Jun 23, 2025

    @laminko
    OwnerAuthor

    ✅ Issue Completed Successfully

    Backend user preferences integration has been fully implemented with comprehensive guest/authenticated user state management:

    🔄 User Preferences Integration Features:

    • Unified State Management: Single composable handling guest and authenticated preferences
    • Automatic Data Migration: Seamless transfer of guest data when users authenticate
    • Real-time Synchronization: Preferences sync between localStorage and database
    • Complete Preference Types: Theme, notifications, currency preferences all integrated
    • Authentication State Watching: Automatic preference loading/clearing on auth changes

    📁 Key Implementation Files:

    • useUserPreferences.ts: Central preference manager with migration system
    • supabaseUserService.ts: Database operations for user preferences
    • useCurrency.ts: Currency preference integration with auth states
    • useAuth.ts: Authentication state management with migration hooks
    • Settings.vue: UI integration showing preference persistence

    🎯 Core Requirements Met:

    🔧 Technical Implementation:

    • initializeUserPreferences(): Complete user setup on authentication
    • migrateGuestPreferences(): Transfers localStorage preferences to database
    • migrateSpendingData(): Historical spending data preservation
    • loadUserPreferences(): Database preference loading with currency sync
    • Authentication Watchers: Automatic preference management on auth changes

    🌟 Advanced Features:

    • Smart Migration: Only migrates when needed, prevents data loss
    • Fallback Systems: LocalStorage fallback for offline functionality
    • Real-time Updates: Preferences update immediately in UI
    • Clean State Management: Proper cleanup on sign-out

    🔗 Related Issues:

    The user preferences system now provides seamless integration between guest and authenticated states with complete data preservation.

    🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0