Fixed the initialisation of the keychain storage in the GetUserUseCase use case

This commit is contained in:
Javier Cicchelli 2022-12-20 03:34:24 +01:00
parent e9a7e8b33b
commit 3ecf5c7468
2 changed files with 9 additions and 15 deletions

View File

@ -95,7 +95,7 @@ private extension ContentView {
do {
user = try await getUser()
} catch {
// TODO: Handle this error appropriately.
showSheet = .login
}
}
}

View File

@ -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)
}
}