From 3ecf5c7468f815795d4cb9cc95a36c9eeacca3d8 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Tue, 20 Dec 2022 03:34:24 +0100 Subject: [PATCH] Fixed the initialisation of the keychain storage in the GetUserUseCase use case --- BeReal/UI/Views/ContentView.swift | 2 +- .../UseCases/Users/GetUserUseCase.swift | 22 +++++++------------ 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/BeReal/UI/Views/ContentView.swift b/BeReal/UI/Views/ContentView.swift index a9316c6..bd0359c 100644 --- a/BeReal/UI/Views/ContentView.swift +++ b/BeReal/UI/Views/ContentView.swift @@ -95,7 +95,7 @@ private extension ContentView { do { user = try await getUser() } catch { - // TODO: Handle this error appropriately. + showSheet = .login } } } diff --git a/Libraries/Sources/UseCases/Users/GetUserUseCase.swift b/Libraries/Sources/UseCases/Users/GetUserUseCase.swift index fe2eaed..0109d6d 100644 --- a/Libraries/Sources/UseCases/Users/GetUserUseCase.swift +++ b/Libraries/Sources/UseCases/Users/GetUserUseCase.swift @@ -14,26 +14,24 @@ import KeychainStorage public actor GetUserUseCase { + // MARK: Storages + + @KeychainStorage(key: .KeychainStorage.account) var account: Account? + // MARK: Properties private let apiService: APIService - private var account: Account? - // MARK: Initialisers - public init( - apiService: APIService, - account: Account? - ) { + public init(apiService: APIService) { self.apiService = apiService - self.account = account } // MARK: Functions public func callAsFunction() async throws -> User { - guard let account else { throw GetUserError .accountNotFound } + guard let account else { throw GetUserError.accountNotFound } return try await getUser( username: account.username, @@ -65,12 +63,8 @@ public actor GetUserUseCase { public extension GetUserUseCase { init() { @Dependency(\.apiService) var apiService - @KeychainStorage(key: .KeychainStorage.account) var account: Account? - - self.init( - apiService: apiService, - account: account - ) + + self.init(apiService: apiService) } }