From 03c53866d2a49f427af943d86c69f7ca5ac53504 Mon Sep 17 00:00:00 2001 From: Nick Cooke Date: Fri, 15 Nov 2024 16:53:25 -0500 Subject: [PATCH] [Auth] Perform view dismiss on MainActor --- .../CustomViews/MFALoginView.swift | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/CustomViews/MFALoginView.swift b/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/CustomViews/MFALoginView.swift index ad01984f989..7695d22af01 100644 --- a/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/CustomViews/MFALoginView.swift +++ b/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/CustomViews/MFALoginView.swift @@ -45,9 +45,7 @@ struct MFALoginView: View { accentColor: .white, backgroundColor: .orange ) { - // TODO(ncooke3): Does this task inherit a higher priority? What about the regular SwiftUI - // button? - Task(priority: .userInitiated, operation: startMfALogin) + Task { await startMfALogin() } } .padding() } else { @@ -59,7 +57,7 @@ struct MFALoginView: View { accentColor: .white, backgroundColor: .orange ) { - Task(priority: .userInitiated, operation: finishMfALogin) + Task { await finishMfALogin() } } .padding() } @@ -112,7 +110,10 @@ extension MFALoginView { let assertion = PhoneMultiFactorGenerator.assertion(with: credential) do { _ = try await resolver.resolveSignIn(with: assertion) - dismiss() + // MFA login was successful. + await MainActor.run { + dismiss() + } } catch { print(error) } @@ -128,7 +129,9 @@ extension MFALoginView { do { _ = try await resolver.resolveSignIn(with: assertion) // MFA login was successful. - dismiss() + await MainActor.run { + dismiss() + } } catch { // Wrong or expired OTP. Re-prompt the user. // TODO(ncooke3): Show error to user.