8000 Implement Currency Preference Database Storage · Issue #41 · laminko/SpendCheck · GitHub
[go: up one dir, main page]

Skip to content

Implement Currency Preference Database Storage #41

Closed

Description

@laminko

Feature: Currency Preference Database Storage

Overview

Save user's selected currency preferences to the database for authenticated users, ensuring preferences persist across sessions and devices.

Parent Issue

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

Current Status

  • ✅ Currency picker UI implemented in Settings
  • ✅ Currency switching works for current session
  • ✅ 21 supported currencies available
  • ❌ Preferences not saved to database for authenticated users
  • ❌ Guest mode still uses localStorage only

Requirements

Database Storage

  • Save currency preference to Supabase for authenticated users
  • Load saved currency on app startup for authenticated users
  • Maintain localStorage fallback for guest users
  • Implement proper RLS policies for user preferences

User Experience

  • Automatic currency loading when user signs in
  • Seamless transition from guest to authenticated user
  • Currency preference migration during sign-up
  • Visual feedback when preference is saved

Data Migration

  • Transfer guest currency selection to user account on authentication
  • Handle conflicts if user has different currencies on different devices
  • Preserve guest preferences until user chooses to override

Technical Implementation

  • Update useCurrency.ts composable for database operations
  • Add currency preference API functions
  • Integrate with user preferences table
  • Update Settings page to show save status
  • Handle online/offline scenarios

Database Integration

user_preferences:
  - currency_code (text) // e.g., 'USD', 'EUR', 'GBP'
  - currency_symbol (text) // e.g., '$', '€', '£'
  - currency_name (text) // e.g., 'US Dollar', 'Euro'

Implementation Details

Currency Loading Priority

  1. Authenticated Users: Database preference
  2. Fallback: localStorage value
  3. Default: USD if no preference found

Save Behavior

  • Guest Users: localStorage only
  • Authenticated Users: Database + localStorage backup
  • Auto-save: Immediate save when currency is changed

Migration Flow

Guest User Changes Currency → localStorage
Guest User Signs In → Transfer localStorage → Database
User Changes Currency → Save to Database

Acceptance Criteria

  • Authenticated users' currency preferences persist across sessions
  • Currency loads automatically when user signs in
  • Guest users can still change currency (localStorage)
  • Smooth migration from guest to authenticated preferences
  • Currency changes are saved immediately for authenticated users
  • Fallback to localStorage works when offline
  • Clear indication in Settings when preference is saved vs local-only

Technical Considerations

  • Handle race conditions during sign-in currency loading
  • Implement proper error handling for database save failures
  • Consider currency preference conflicts across devices
  • Optimize database queries for quick app startup
  • Maintain backward compatibility with existing localStorage usage

Priority

High - Users expect their preferences to be saved

Dependencies

  • Database schema for user_preferences table
  • User preferences integration composable updates

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

    Currency preference database storage has been fully implemented with seamless guest/authenticated user support:

    💰 Currency Storage Features Implemented:

    • Database Storage: Authenticated users' currency preferences saved to Supabase
    • LocalStorage Fallback: Guest users continue using localStorage
    • Automatic Migration: Guest preferences migrate to database upon authentication
    • 21 Supported Currencies: Complete currency list with proper symbols and formatting
    • Smart Formatting: Handles different currency formats (JPY/KRW no decimals, metric abbreviations)

    📁 Key Implementation Files:

    • useCurrency.ts: Complete currency management with database/localStorage logic
    • supabaseUserService.ts: Database operations for user preferences including currency
    • useUserPreferences.ts: Migration system for guest → authenticated users
    • Settings.vue: Currency picker UI integrated with database storage

    🎯 Core Requirements Met:

    • ✅ Database storage for authenticated users via Supabase user_preferences table
    • ✅ LocalStorage fallback for guest users
    • ✅ Seamless migration when guest users authenticate
    • ✅ Currency preference persistence across sessions
    • ✅ Proper error handling with fallback to localStorage
    • ✅ Real-time currency updates in UI

    🔧 Technical Implementation:

    • setCurrency(): Async function handling both database and localStorage
    • loadSavedCurrency(): Loads from database first, falls back to localStorage
    • Database Schema: currency_code, currency_symbol, currency_name fields
    • Migration Logic: Automatic guest preference transfer on authentication

    🔗 Related Issues:

    Currency preferences now work seamlessly for both guest and authenticated users with proper database persistence.

    🤖 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