Skip to content

Mobile: Native storage abstraction (Capacitor Preferences)#74

Merged
brianorwhatever merged 2 commits intomainfrom
mobile/native-storage
Feb 8, 2026
Merged

Mobile: Native storage abstraction (Capacitor Preferences)#74
brianorwhatever merged 2 commits intomainfrom
mobile/native-storage

Conversation

@krusty-agent
Copy link
Copy Markdown
Collaborator

Overview

This PR adds a native storage abstraction layer that provides a unified interface for both web and native platforms:

  • Web: Uses localStorage (synchronous)
  • Native (iOS/Android): Uses Capacitor Preferences (async, secure native storage)

Changes

New Files

  • src/lib/storageAdapter.ts: Low-level async storage adapter

    • WebStorage: Wraps localStorage in async API for web
    • NativeStorage: Uses Capacitor Preferences on native platforms
    • Auto-detects platform using Capacitor.isNativePlatform()
  • src/lib/STORAGE_MIGRATION.md: Migration guide and documentation

    • Explains the storage abstraction
    • Provides migration examples
    • Lists files marked for future migration

Modified Files

  • package.json: Added @capacitor/preferences dependency
  • src/lib/storage.ts: Added TODO comments for migration
  • src/hooks/useAuth.tsx: Added TODO comments for migration
  • src/lib/webvh.ts: Added TODO comments for migration

Strategy

Rather than breaking existing code, this PR:

  1. Creates the storage abstraction infrastructure
  2. Marks existing localStorage usage with TODO comments
  3. Provides a clear migration path for future PRs

This allows:

  • Existing synchronous code to keep working
  • New code to use the async adapter
  • Incremental migration of existing code

Testing

  • ✅ Build passes (npm run build)
  • ✅ Package installed successfully
  • Ready for testing on native platforms

Next Steps

Future PRs can migrate existing code incrementally:

  1. Settings (storage.ts) - Most impactful, easiest
  2. WebVH Keys (webvh.ts) - Security-critical
  3. Auth State (useAuth.tsx) - Complex, needs careful testing

Benefits

  • Better security on native platforms (encrypted storage)
  • Platform consistency across web and native
  • Foundation for future platform support
  • Respects OS-level privacy controls

- Install @capacitor/preferences package
- Create storageAdapter.ts with unified async storage interface
  - Uses Capacitor Preferences on native platforms
  - Uses localStorage on web (wrapped in async API)
- Add migration guide (STORAGE_MIGRATION.md)
- Mark existing localStorage usage with TODO comments for future migration:
  - src/lib/storage.ts (settings functions)
  - src/hooks/useAuth.tsx (JWT and auth state)
  - src/lib/webvh.ts (private key storage)

The storage adapter provides a foundation for native storage support
without breaking existing synchronous code. Files can be migrated to
use the async adapter incrementally.
@krusty-agent krusty-agent force-pushed the mobile/native-storage branch from b38a580 to 25544df Compare February 8, 2026 15:56
@brianorwhatever brianorwhatever merged commit 50c66f7 into main Feb 8, 2026
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants