-
Notifications
You must be signed in to change notification settings - Fork 482
/
Copy pathUpdatePassword.swift
82 lines (71 loc) · 1.99 KB
/
UpdatePassword.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//
// UpdatePassword.swift
// FirebaseUI
//
// Created by Russell Wheatley on 24/04/2025.
//
import SwiftUI
private enum FocusableField: Hashable {
case password
case confirmPassword
}
@MainActor
public struct UpdatePasswordView {
@Environment(AuthService.self) private var authService
@State private var password = ""
@State private var confirmPassword = ""
@FocusState private var focus: FocusableField?
private var isValid: Bool {
!password.isEmpty && password == confirmPassword
}
}
extension UpdatePasswordView: View {
private var isShowingPasswordPrompt: Binding<Bool> {
Binding(
get: { authService.passwordPrompt.isPromptingPassword },
set: { authService.passwordPrompt.isPromptingPassword = $0 }
)
}
public var body: some View {
VStack {
LabeledContent {
SecureField("Password", text: $password)
.focused($focus, equals: .password)
.submitLabel(.go)
} label: {
Image(systemName: "lock")
}
.padding(.vertical, 6)
.background(Divider(), alignment: .bottom)
.padding(.bottom, 8)
Divider()
LabeledContent {
SecureField("Confirm password", text: $confirmPassword)
.focused($focus, equals: .confirmPassword)
.submitLabel(.go)
} label: {
Image(systemName: "lock")
}
.padding(.vertical, 6)
.background(Divider(), alignment: .bottom)
.padding(.bottom, 8)
Divider()
Button(action: {
Task {
try await authService.updatePassword(to: confirmPassword)
authService.authView = .authPicker
}
}, label: {
Text("Update password")
.padding(.vertical, 8)
.frame(maxWidth: .infinity)
})
.disabled(!isValid)
.padding([.top, .bottom], 8)
.frame(maxWidth: .infinity)
.buttonStyle(.borderedProminent)
}.sheet(isPresented: isShowingPasswordPrompt) {
PasswordPromptSheet(coordinator: authService.passwordPrompt)
}
}
}