From 253401150697eed3805c9233f419f66ae5cb7fde Mon Sep 17 00:00:00 2001 From: Simon Franken Date: Wed, 18 Feb 2026 21:53:01 +0100 Subject: [PATCH] fix --- .../TimeTracker/Core/Auth/AuthService.swift | 19 +++++++++---------- .../TimeTracker/Features/Auth/LoginView.swift | 19 ++++++++----------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/ios/TimeTracker/TimeTracker/Core/Auth/AuthService.swift b/ios/TimeTracker/TimeTracker/Core/Auth/AuthService.swift index 2f5db7a..f77bdfa 100644 --- a/ios/TimeTracker/TimeTracker/Core/Auth/AuthService.swift +++ b/ios/TimeTracker/TimeTracker/Core/Auth/AuthService.swift @@ -12,7 +12,7 @@ final class AuthService: NSObject { super.init() } - func login(presentationAnchor: ASPresentationAnchor) async throws { + func login(presentationAnchor: ASPresentationAnchor?) async throws { self.presentationAnchor = presentationAnchor let codeVerifier = generateCodeVerifier() @@ -79,15 +79,14 @@ final class AuthService: NSObject { self.authSession = webAuthSession - webAuthSession.start { started in - if !started { - DispatchQueue.main.async { - NotificationCenter.default.post( - name: .authError, - object: nil, - userInfo: ["error": AuthError.failed("Failed to start auth session")] - ) - } + let started = webAuthSession.start() + if !started { + DispatchQueue.main.async { + NotificationCenter.default.post( + name: .authError, + object: nil, + userInfo: ["error": AuthError.failed("Failed to start auth session")] + ) } } } diff --git a/ios/TimeTracker/TimeTracker/Features/Auth/LoginView.swift b/ios/TimeTracker/TimeTracker/Features/Auth/LoginView.swift index d3b4fc8..d45eeb5 100644 --- a/ios/TimeTracker/TimeTracker/Features/Auth/LoginView.swift +++ b/ios/TimeTracker/TimeTracker/Features/Auth/LoginView.swift @@ -55,6 +55,12 @@ struct LoginView: View { .onReceive(NotificationCenter.default.publisher(for: .authCallbackReceived)) { notification in handleAuthCallback(notification.userInfo) } + .onReceive(NotificationCenter.default.publisher(for: .authError)) { notification in + if let authError = notification.userInfo?["error"] as? AuthError { + isLoading = false + errorMessage = authError.errorDescription + } + } } private func login() { @@ -62,21 +68,12 @@ struct LoginView: View { errorMessage = nil Task { - do { - let authService = AuthService.shared - await authService.login(presentationAnchor: nil as! ASPresentationAnchor) - } catch { - await MainActor.run { - isLoading = false - errorMessage = error.localizedDescription - } - } + let authService = AuthService.shared + await authService.login(presentationAnchor: nil) } } private func handleAuthCallback(_ userInfo: [AnyHashable: Any]?) { - // Handle OAuth callback - // In practice, this would exchange the code for tokens Task { await authManager.checkAuthState() await MainActor.run {