mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
Uses Keychain.patreonAccountID to fetch current user’s PatreonAccount
Allows us to distinguish between the current user and other cached patrons in the future.
This commit is contained in:
@@ -74,6 +74,9 @@ public class Keychain
|
||||
@KeychainItem(key: "patreonCreatorAccessToken")
|
||||
public var patreonCreatorAccessToken: String?
|
||||
|
||||
@KeychainItem(key: "patreonAccountID")
|
||||
public var patreonAccountID: String?
|
||||
|
||||
private init()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -151,8 +151,12 @@ public extension DatabaseManager
|
||||
|
||||
func patreonAccount(in context: NSManagedObjectContext = DatabaseManager.shared.viewContext) -> PatreonAccount?
|
||||
{
|
||||
let patronAccount = PatreonAccount.first(in: context)
|
||||
return patronAccount
|
||||
guard let patreonAccountID = Keychain.shared.patreonAccountID else { return nil }
|
||||
|
||||
let predicate = NSPredicate(format: "%K == %@", #keyPath(PatreonAccount.identifier), patreonAccountID)
|
||||
|
||||
let patreonAccount = PatreonAccount.first(satisfying: predicate, in: context)
|
||||
return patreonAccount
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -120,7 +120,15 @@ public extension PatreonAPI
|
||||
Keychain.shared.patreonAccessToken = accessToken
|
||||
Keychain.shared.patreonRefreshToken = refreshToken
|
||||
|
||||
self.fetchAccount(completion: completion)
|
||||
self.fetchAccount { (result) in
|
||||
switch result
|
||||
{
|
||||
case .success(let account): Keychain.shared.patreonAccountID = account.identifier
|
||||
case .failure: break
|
||||
}
|
||||
|
||||
completion(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -238,8 +246,10 @@ public extension PatreonAPI
|
||||
DatabaseManager.shared.persistentContainer.performBackgroundTask { (context) in
|
||||
do
|
||||
{
|
||||
let accounts = PatreonAccount.all(in: context, requestProperties: [\FetchRequest.returnsObjectsAsFaults: true])
|
||||
accounts.forEach(context.delete(_:))
|
||||
if let account = DatabaseManager.shared.patreonAccount(in: context)
|
||||
{
|
||||
context.delete(account)
|
||||
}
|
||||
|
||||
self.deactivateBetaApps(in: context)
|
||||
|
||||
@@ -247,6 +257,7 @@ public extension PatreonAPI
|
||||
|
||||
Keychain.shared.patreonAccessToken = nil
|
||||
Keychain.shared.patreonRefreshToken = nil
|
||||
Keychain.shared.patreonAccountID = nil
|
||||
|
||||
completion(.success(()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user