From fc152769a6310157260d8bcee1f7074f96240e9a Mon Sep 17 00:00:00 2001 From: sinLuke Date: Wed, 27 Nov 2024 13:29:22 -0800 Subject: [PATCH] Fix thread related warnings in AuthenticationHandler --- FollowUI/Sources/FollowUI/LandingView.swift | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/FollowUI/Sources/FollowUI/LandingView.swift b/FollowUI/Sources/FollowUI/LandingView.swift index d7c53e4..a457853 100644 --- a/FollowUI/Sources/FollowUI/LandingView.swift +++ b/FollowUI/Sources/FollowUI/LandingView.swift @@ -106,9 +106,11 @@ class AuthenticationHandler: NSObject, ObservableObject, @unchecked Sendable { private func loadSessionData() async { if let sessionData = KeychainWrapper.load(forKey: "sessionData") { - self.sessionData = try? JSONDecoder().decode( - Auth.SessionResponse.self, from: sessionData - ) + await MainActor.run { + self.sessionData = try? JSONDecoder().decode( + Auth.SessionResponse.self, from: sessionData + ) + } } if let sessionTokenData = KeychainWrapper.load(forKey: "sessionToken") { do { @@ -116,9 +118,13 @@ class AuthenticationHandler: NSObject, ObservableObject, @unchecked Sendable { String.self, from: sessionTokenData ) NetworkManager.shared.setSessionToken(sessionToken) - isAuthenticated = true + await MainActor.run { + isAuthenticated = true + } } catch { - isAuthenticated = false + await MainActor.run { + isAuthenticated = false + } } } else { isAuthenticated = false