Skip to content

Commit 28fb71a

Browse files
PasswordRecoveryView implementation
1 parent c69360f commit 28fb71a

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/FirebaseAuthSwiftUI/Views/PasswordRecoveryView.swift

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
import SwiftUI
22

3-
public struct PasswordRecoveryView: View {
3+
public struct PasswordRecoveryView {
4+
@Environment(AuthEnvironment.self) private var authEnvironment
45
@State private var email = ""
6+
@State private var errorMessage = ""
7+
8+
private var provider: EmailPasswordAuthProvider
9+
10+
public init(provider: EmailPasswordAuthProvider) {
11+
self.provider = provider
12+
}
13+
14+
private func sendPasswordRecoveryEmail() async {
15+
do {
16+
try await provider.sendPasswordRecoveryEmail(withEmail: email)
17+
} catch {
18+
errorMessage = error.localizedDescription
19+
}
20+
}
21+
}
22+
23+
extension PasswordRecoveryView: View {
524
public var body: some View {
625
VStack {
726
Text("Password Recovery")
@@ -15,6 +34,26 @@ public struct PasswordRecoveryView: View {
1534
}.padding(.vertical, 6)
1635
.background(Divider(), alignment: .bottom)
1736
.padding(.bottom, 4)
37+
Button(action: {
38+
Task {
39+
await sendPasswordRecoveryEmail()
40+
}
41+
}) {
42+
if authEnvironment.authenticationState != .authenticating {
43+
Text("Password Recovery")
44+
.padding(.vertical, 8)
45+
.frame(maxWidth: .infinity)
46+
} else {
47+
ProgressView()
48+
.progressViewStyle(CircularProgressViewStyle(tint: .white))
49+
.padding(.vertical, 8)
50+
.frame(maxWidth: .infinity)
51+
}
52+
}
53+
.disabled(!EmailUtils.isValidEmail(email))
54+
.padding([.top, .bottom], 8)
55+
.frame(maxWidth: .infinity)
56+
.buttonStyle(.borderedProminent)
1857
}
1958
}
2059
}

0 commit comments

Comments
 (0)