Skip to content

Commit

Permalink
Add some loggigns
Browse files Browse the repository at this point in the history
  • Loading branch information
mohannad-hassan committed Dec 24, 2024
1 parent f5e5900 commit 38efebd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Data/OAuthClient/Sources/AppAuthOAuthClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Foundation
import UIKit
import AppAuth
import VLogging

public final class AppAuthOAuthClient: OAuthClient {

Expand All @@ -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
}

Expand All @@ -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)
}
}
Expand All @@ -63,17 +69,20 @@ public final class AppAuthOAuthClient: OAuthClient {
responseType: OIDResponseTypeCode,
additionalParameters: [:])

logger.info("Starting OAuth flow")
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, any Error>) 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()
}
}
Expand Down
2 changes: 2 additions & 0 deletions Features/SettingsFeature/SettingsRootViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down

0 comments on commit 38efebd

Please sign in to comment.