@@ -79,6 +79,40 @@ import Foundation
7979 fatalError ( " Internal Auth error: failed to get user enrolling in MultiFactor " )
8080 }
8181
82+ let request = Self . enrollmentFinalizationRequest (
83+ with: assertion,
84+ displayName: displayName,
85+ user: user,
86+ auth: auth
87+ )
88+
89+ Task {
90+ do {
91+ let response = try await auth. backend. call ( with: request)
92+ let user = try await auth. completeSignIn ( withAccessToken: response. idToken,
93+ accessTokenExpirationDate: nil ,
94+ refreshToken: response. refreshToken,
95+ anonymous: false )
96+ try auth. updateCurrentUser ( user, byForce: false , savingToDisk: true )
97+ if let completion {
98+ DispatchQueue . main. async {
99+ completion ( nil )
100+ }
101+ }
102+ } catch {
103+ if let completion {
104+ DispatchQueue . main. async {
105+ completion ( error)
106+ }
107+ }
108+ }
109+ }
110+ }
111+
112+ private static func enrollmentFinalizationRequest( with assertion: MultiFactorAssertion ,
113+ displayName: String ? ,
114+ user: User ,
115+ auth: Auth ) -> FinalizeMFAEnrollmentRequest {
82116 var request : FinalizeMFAEnrollmentRequest ? = nil
83117 if assertion. factorID == PhoneMultiFactorInfo . TOTPMultiFactorID {
84118 guard let totpAssertion = assertion as? TOTPMultiFactorAssertion else {
@@ -121,30 +155,10 @@ import Foundation
121155
122156 guard let request else {
123157 // Assertion is not a phone assertion or TOTP assertion.
124- return
158+ fatalError ( " Internal Error: Unsupported assertion with factor ID: \( assertion . factorID ) . " )
125159 }
126160
127- Task {
128- do {
129- let response = try await auth. backend. call ( with: request)
130- let user = try await auth. completeSignIn ( withAccessToken: response. idToken,
131- accessTokenExpirationDate: nil ,
132- refreshToken: response. refreshToken,
133- anonymous: false )
134- try auth. updateCurrentUser ( user, byForce: false , savingToDisk: true )
135- if let completion {
136- DispatchQueue . main. async {
137- completion ( nil )
138- }
139- }
140- } catch {
141- if let completion {
142- DispatchQueue . main. async {
143- completion ( error)
144- }
145- }
146- }
147- }
161+ return request
148162 }
149163
150164 /// Enrolls a second factor as identified by the `MultiFactorAssertion` parameter for the
0 commit comments