Skip to content

Commit

Permalink
fix: Stop using account.token (#1486)
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinperignon committed Jul 11, 2024
2 parents 73339e2 + eb3b2f3 commit 8f85918
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
6 changes: 1 addition & 5 deletions MailCore/Cache/AccountManager/AccountManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ public final class AccountManager: RefreshTokenDelegate, ObservableObject {
}

public func removeTokenAndAccount(account: Account) {
let removedToken = tokenStore.removeTokenFor(userId: account.userId) ?? account.token
let removedToken = tokenStore.removeTokenFor(userId: account.userId)
removeAccount(toDeleteAccount: account)

guard let removedToken else {
Expand All @@ -526,10 +526,6 @@ public final class AccountManager: RefreshTokenDelegate, ObservableObject {
}
}

public func account(for token: ApiToken) -> Account? {
return accounts.values.first { $0.token.userId == token.userId }
}

public func account(for userId: Int) -> Account? {
return accounts.values.first { $0.userId == userId }
}
Expand Down
5 changes: 4 additions & 1 deletion MailCore/Utils/URLSchemeHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

import Foundation
import InfomaniakCore
import InfomaniakDI
import WebKit

Expand All @@ -28,14 +29,16 @@ public final class URLSchemeHandler: NSObject, WKURLSchemeHandler {
private let syncQueue = DispatchQueue(label: "com.infomaniak.mail.URLSchemeHandler")

@LazyInjectService private var accountManager: AccountManager
@LazyInjectService private var tokenStore: TokenStore

public func webView(_ webView: WKWebView, start urlSchemeTask: WKURLSchemeTask) {
guard let url = urlSchemeTask.request.url else {
urlSchemeTask.didFailWithError(MailError.resourceError)
return
}

guard let currentAccessToken = accountManager.getCurrentAccount()?.token?.accessToken else {
guard let currentAccount = accountManager.getCurrentAccount(),
let currentAccessToken = tokenStore.tokenFor(userId: currentAccount.userId)?.accessToken else {
urlSchemeTask.didFailWithError(MailError.unknownError)
return
}
Expand Down

0 comments on commit 8f85918

Please sign in to comment.