Fixes authenticating with old email address after changing Apple ID’s primary email

This commit is contained in:
Riley Testut
2022-05-25 16:45:27 -07:00
parent 994d3c74fd
commit 9c1fe4d63b

View File

@@ -49,6 +49,7 @@ class AuthenticationOperation: ResultOperation<(ALTTeam, ALTCertificate, ALTAppl
private lazy var storyboard = UIStoryboard(name: "Authentication", bundle: nil) private lazy var storyboard = UIStoryboard(name: "Authentication", bundle: nil)
private var appleIDEmailAddress: String?
private var appleIDPassword: String? private var appleIDPassword: String?
private var shouldShowInstructions = false private var shouldShowInstructions = false
@@ -174,6 +175,13 @@ class AuthenticationOperation: ResultOperation<(ALTTeam, ALTCertificate, ALTAppl
} }
account.update(account: altTeam.account) account.update(account: altTeam.account)
if let providedEmailAddress = self.appleIDEmailAddress
{
// Save the user's provided email address instead of the one associated with their account (which may be outdated).
account.appleID = providedEmailAddress
}
team.update(team: altTeam) team.update(team: altTeam)
try context.save() try context.save()
@@ -242,7 +250,7 @@ class AuthenticationOperation: ResultOperation<(ALTTeam, ALTCertificate, ALTAppl
try context.save() try context.save()
// Update keychain // Update keychain
Keychain.shared.appleIDEmailAddress = altTeam.account.appleID Keychain.shared.appleIDEmailAddress = self.appleIDEmailAddress ?? altTeam.account.appleID // Prefer the user's provided email address over the one associated with their account (which may be outdated).
Keychain.shared.appleIDPassword = self.appleIDPassword Keychain.shared.appleIDPassword = self.appleIDPassword
Keychain.shared.signingCertificate = altCertificate.p12Data() Keychain.shared.signingCertificate = altCertificate.p12Data()
@@ -359,6 +367,8 @@ private extension AuthenticationOperation
func authenticate(appleID: String, password: String, completionHandler: @escaping (Result<(ALTAccount, ALTAppleAPISession), Swift.Error>) -> Void) func authenticate(appleID: String, password: String, completionHandler: @escaping (Result<(ALTAccount, ALTAppleAPISession), Swift.Error>) -> Void)
{ {
self.appleIDEmailAddress = appleID
let fetchAnisetteDataOperation = FetchAnisetteDataOperation(context: self.context) let fetchAnisetteDataOperation = FetchAnisetteDataOperation(context: self.context)
fetchAnisetteDataOperation.resultHandler = { (result) in fetchAnisetteDataOperation.resultHandler = { (result) in
switch result switch result