Phase 5: Authentication

Status: Complete iOS PRs: #338 (Dark Mode), #339 (Authentication), #340 (Apple Sign-In)


Overview

Phase 5 implements iOS authentication with Firebase, including Google Sign-In OAuth, Apple Sign-In, anonymous (guest) authentication, and dark mode settings.


Features

PR #338 - Dark Mode Toggle

  • ThemeManager with @AppStorage persistence
  • System/Light/Dark theme options
  • Immediate visual feedback
  • 14 TDD tests

PR #339 - Authentication Flow

  • Google Sign-In OAuth
  • Anonymous (guest) authentication
  • Account upgrade from guest to Google
  • Real-time auth state observation
  • Swift-native Firebase implementation
  • 14 TDD tests

PR #340 - Apple Sign-In

  • Native AuthenticationServices framework
  • Cryptographic nonce security (SecRandomCopyBytes + SHA256)
  • Continuation-based delegate → async/await bridging
  • Firebase OAuthProvider credential exchange
  • Race condition prevention
  • iPad navigation fixes (NavigationStack)
  • 6 TDD tests

Architecture

SignInView                          SettingsTabView
     │                                    │
     ▼                                    ▼
SignInViewModel                    ThemeManager
     │                                    │
     ▼                                    ▼
FirebaseAuthRepositoryBridge      @AppStorage
     │                            (UserDefaults)
     ├── GoogleSignInProviderImpl
     ├── AppleSignInProviderImpl
     └── Firebase Auth SDK

Key Files

ComponentFileDescription
Auth BridgeAuth/FirebaseAuthRepositoryBridge.swiftSwift-native Firebase
Google ProviderAuth/GoogleSignInProviderImpl.swiftGoogle OAuth tokens
Apple ProviderAuth/AppleSignInProviderImpl.swiftApple Sign-In + nonce
Sign-In ViewScreens/SignInView.swiftUI + ViewModel
Theme ManagerThemeManager.swiftDark mode
Settings ViewScreens/SettingsTabView.swiftTheme picker

Test Coverage

ComponentTestsFile
SignInViewModel20SignInViewModelTests.swift
ThemeManager14ThemeManagerTests.swift

Total: 34 TDD tests


Key Patterns

  1. Swift-Native Firebase - Avoid KMP ObjCExportCoroutines issues
  2. Native Auth State Listener - Use Firebase SDK directly
  3. @AppStorage + objectWillChange - Proper SwiftUI observation
  4. Token Flow Optimization - Single signIn() returns both tokens
  5. Nonce Security - Prevent replay attacks with SHA256 verification
  6. Continuation Bridging - Delegate → async/await with CheckedContinuation
  7. NavigationStack - Avoid iPad split view issues

Documentation



Last Updated: 2025-12-02

2 items under this folder.