@@ -32,13 +32,25 @@ public struct UpdatePasswordView {
3232 @Environment ( AuthService . self) private var authService
3333 @State private var password = " "
3434 @State private var confirmPassword = " "
35+ @State private var showAlert = false
3536
3637 @FocusState private var focus : FocusableField ?
3738
3839 private var isValid : Bool {
3940 FormValidators . atLeast6Characters. isValid ( input: password) &&
4041 FormValidators . confirmPassword ( password: password) . isValid ( input: confirmPassword)
4142 }
43+
44+ private func updatePassword( ) {
45+ Task {
46+ do {
47+ try await authService. updatePassword ( to: confirmPassword)
48+ showAlert = true
49+ } catch {
50+
51+ }
52+ }
53+ }
4254}
4355
4456extension UpdatePasswordView : View {
@@ -80,15 +92,11 @@ extension UpdatePasswordView: View {
8092 . focused ( $focus, equals: . confirmPassword)
8193
8294 Button ( action: {
83- Task {
84- try await authService. updatePassword ( to: confirmPassword)
85- authService. navigator. clear ( )
86- }
95+ updatePassword ( )
8796 } , label: {
8897 Text ( authService. string. updatePasswordButtonLabel)
8998 . padding ( . vertical, 8 )
9099 . frame ( maxWidth: . infinity)
91-
92100 } )
93101 . disabled ( !isValid)
94102 . padding ( [ . top, . bottom] , 8 )
@@ -98,6 +106,17 @@ extension UpdatePasswordView: View {
98106 . frame ( maxWidth: . infinity, maxHeight: . infinity, alignment: . top)
99107 . safeAreaPadding ( )
100108 . navigationTitle ( authService. string. passwordRecoveryTitle)
109+ . alert (
110+ " Password Updated " ,
111+ isPresented: $showAlert
112+ ) {
113+ Button ( authService. string. okButtonLabel) {
114+ showAlert = false
115+ authService. navigator. clear ( )
116+ }
117+ } message: {
118+ Text ( " Your password has been successfully updated. " )
119+ }
101120 . sheet ( isPresented: $passwordPrompt. isPromptingPassword) {
102121 PasswordPromptSheet ( coordinator: authService. passwordPrompt)
103122 }
0 commit comments