05/17 Fix bugs 4

This commit is contained in:
Nguyen Ngo
2026-05-17 11:21:16 -04:00
parent f436ac2ef2
commit 437ed913cd
@@ -1035,7 +1035,14 @@ struct SettingsView: View {
Section { Section {
Button(role: .destructive) { Button(role: .destructive) {
Task { await auth.logout() } Task {
// Clear server-pulled issues before logging out so stale
// records from a previous server/domain don't persist into
// the next session. Device-created pending issues are preserved.
clearServerPulledData()
sync.resetNotificationPoller()
await auth.logout()
}
} label: { } label: {
Label("Log Out", systemImage: "rectangle.portrait.and.arrow.right") Label("Log Out", systemImage: "rectangle.portrait.and.arrow.right")
} }
@@ -1073,4 +1080,17 @@ struct SettingsView: View {
Task { await sync.pullReferenceData() } Task { await sync.pullReferenceData() }
} }
} }
/// Delete all server-pulled LocalIssue records (syncStatus == "synced" and
/// inspectionLocalId == ""). These are issues fetched from the server and
/// reconciled by pullAssignedIssues they must be cleared on logout so
/// stale records from a previous server domain or user session don't persist.
/// Device-created issues (inspectionLocalId != "") are never touched.
private func clearServerPulledData() {
let allIssues = (try? context.fetch(FetchDescriptor<LocalIssue>())) ?? []
allIssues
.filter { $0.syncStatus == "synced" && $0.inspectionLocalId == "" }
.forEach { context.delete($0) }
try? context.save()
}
} }