05/08 Updated code: fix some issues 3

This commit is contained in:
Nguyen Ngo
2026-05-08 16:44:02 -04:00
parent 346eb270ee
commit 606eda9521
9 changed files with 200 additions and 353 deletions
+13 -3
View File
@@ -1,16 +1,14 @@
// ContentView.swift
// -----------------
// Root view. Shows LoginView or DashboardView based on auth state.
import SwiftUI
struct ContentView: View {
@EnvironmentObject private var auth: AuthManager
@EnvironmentObject private var sync: SyncManager
var body: some View {
Group {
if auth.isLoading && !auth.isAuthenticated {
// Splash / loading state on app launch
VStack(spacing: 16) {
Image(systemName: "checkmark.seal.fill")
.font(.system(size: 64))
@@ -24,5 +22,17 @@ struct ContentView: View {
}
}
.animation(.easeInOut(duration: 0.3), value: auth.isAuthenticated)
.task {
// 1. Restore session first sets isAuthenticated and loads tokens.
await AuthManager.shared.restoreSession()
// 2. Only start network monitoring AFTER auth is resolved.
// startMonitoring() fires triggerSync() immediately on connectivity,
// so it must not run before tokens are in place.
SyncManager.shared.startMonitoring()
// 3. If already online and authenticated, do an initial sync.
if SyncManager.shared.isOnline && AuthManager.shared.isAuthenticated {
await SyncManager.shared.triggerSync()
}
}
}
}