From 38efebdee61b1eab2f3d39ac956886f91a645c62 Mon Sep 17 00:00:00 2001 From: "Mohannad A. Hassan" Date: Tue, 24 Dec 2024 04:53:54 +0200 Subject: [PATCH] Add some loggigns --- Data/OAuthClient/Sources/AppAuthOAuthClient.swift | 13 +++++++++++-- .../SettingsFeature/SettingsRootViewModel.swift | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Data/OAuthClient/Sources/AppAuthOAuthClient.swift b/Data/OAuthClient/Sources/AppAuthOAuthClient.swift index fbcba1c1..e1fda305 100644 --- a/Data/OAuthClient/Sources/AppAuthOAuthClient.swift +++ b/Data/OAuthClient/Sources/AppAuthOAuthClient.swift @@ -8,6 +8,7 @@ import Foundation import UIKit import AppAuth +import VLogging public final class AppAuthOAuthClient: OAuthClient { @@ -23,6 +24,7 @@ public final class AppAuthOAuthClient: OAuthClient { public func login(on viewController: UIViewController) async throws { guard let configuration = self.appConfiguration else { + logger.error("login invoked without OAuth client configurations being set") throw OAuthClientError.oauthClientHasNotBeenSet } @@ -34,18 +36,22 @@ public final class AppAuthOAuthClient: OAuthClient { } private func discoverConfiguration(forIssuer issuer: URL) async throws -> OIDServiceConfiguration { - try await withCheckedThrowingContinuation { continuation in + logger.info("Discovering configuration for OAuth") + return try await withCheckedThrowingContinuation { continuation in OIDAuthorizationService .discoverConfiguration(forIssuer: issuer) { configuration, error in guard error == nil else { + logger.error("Error fetching OAuth configuration: \(error!)") continuation.resume(throwing: OAuthClientError.errorFetchingConfiguration(error)) return } guard let configuration = configuration else { // This should not happen + logger.error("Error fetching OAuth configuration: no cofniguration was loaded. An unexpected situtation.") continuation.resume(throwing: OAuthClientError.errorFetchingConfiguration(nil)) return } + logger.info("OAuth configuration fetched successfully") continuation.resume(returning: configuration) } } @@ -63,17 +69,20 @@ public final class AppAuthOAuthClient: OAuthClient { responseType: OIDResponseTypeCode, additionalParameters: [:]) + logger.info("Starting OAuth flow") try await withCheckedThrowingContinuation { (continuation: CheckedContinuation) in fire(loginRequest: request, on: viewController) { state, error in guard error == nil else { + logger.error("Error authenticating: \(error!)") continuation.resume(throwing: OAuthClientError.errorAuthenticating(error)) return } guard let state = state else { + logger.error("Error authenticating: no state returned. An unexpected situtation.") continuation.resume(throwing: OAuthClientError.errorAuthenticating(nil)) return } - print(state) + logger.info("OAuth flow completed successfully") continuation.resume() } } diff --git a/Features/SettingsFeature/SettingsRootViewModel.swift b/Features/SettingsFeature/SettingsRootViewModel.swift index 66b4c6b2..ff33f807 100644 --- a/Features/SettingsFeature/SettingsRootViewModel.swift +++ b/Features/SettingsFeature/SettingsRootViewModel.swift @@ -133,11 +133,13 @@ final class SettingsRootViewModel: ObservableObject { } func loginToQuranCom() async { + logger.info("Settings: Login to Quran.com") guard let viewController = navigationController else { return } do { try await self.quranProfileService.login(on: viewController) + // TODO: Replace with the needed UI changes. print("Login seems successful") } catch { logger.error("Failed to login to Quran.com: \(error)")