@@ -77,18 +77,14 @@ public struct MFAEnrolmentView {
7777 private func startEnrollment( ) {
7878 Task {
7979 isLoading = true
80-
81- do {
82- let session = try await authService. startMfaEnrollment (
83- type: selectedFactorType,
84- accountName: authService. currentUser? . email,
85- issuer: authService. configuration. mfaIssuer
86- )
87- currentSession = session
88- isLoading = false
89- } catch {
90- isLoading = false
91- }
80+ defer { isLoading = false }
81+
82+ let session = try await authService. startMfaEnrollment (
83+ type: selectedFactorType,
84+ accountName: authService. currentUser? . email,
85+ issuer: authService. configuration. mfaIssuer
86+ )
87+ currentSession = session
9288 }
9389 }
9490
@@ -97,28 +93,24 @@ public struct MFAEnrolmentView {
9793
9894 Task {
9995 isLoading = true
100-
101- do {
102- let verificationId = try await authService. sendSmsVerificationForEnrollment (
103- session: session,
104- phoneNumber: phoneNumber
105- )
106- // Update session status
107- currentSession = EnrollmentSession (
108- id: session. id,
109- type: session. type,
110- session: session. session,
111- totpInfo: session. totpInfo,
112- phoneNumber: phoneNumber,
113- verificationId: verificationId,
114- status: . verificationSent,
115- createdAt: session. createdAt,
116- expiresAt: session. expiresAt
117- )
118- isLoading = false
119- } catch {
120- isLoading = false
121- }
96+ defer { isLoading = false }
97+
98+ let verificationId = try await authService. sendSmsVerificationForEnrollment (
99+ session: session,
100+ phoneNumber: phoneNumber
101+ )
102+ // Update session status
103+ currentSession = EnrollmentSession (
104+ id: session. id,
105+ type: session. type,
106+ session: session. session,
107+ totpInfo: session. totpInfo,
108+ phoneNumber: phoneNumber,
109+ verificationId: verificationId,
110+ status: . verificationSent,
111+ createdAt: session. createdAt,
112+ expiresAt: session. expiresAt
113+ )
122114 }
123115 }
124116
@@ -127,25 +119,20 @@ public struct MFAEnrolmentView {
127119
128120 Task {
129121 isLoading = true
122+ defer { isLoading = false }
130123
131- do {
132- let code = session. type == . sms ? verificationCode : totpCode
133- try await authService. completeEnrollment (
134- session: session,
135- verificationId: session. verificationId,
136- verificationCode: code,
137- displayName: displayName
138- )
139-
140- // Reset form state on success
141- resetForm ( )
142-
143- // Navigate back to signed in view
144- authService. authView = . authPicker
145- isLoading = false
146- } catch {
147- isLoading = false
148- }
124+ let code = session. type == . sms ? verificationCode : totpCode
125+ try await authService. completeEnrollment (
126+ session: session,
127+ verificationId: session. verificationId,
128+ verificationCode: code,
129+ displayName: displayName
130+ )
131+
132+ // Reset form state on success
133+ resetForm ( )
134+
135+ authService. authView = . authPicker
149136 }
150137 }
151138
0 commit comments