-
Notifications
You must be signed in to change notification settings - Fork 491
Expand file tree
/
Copy pathEmailLinkView.swift
More file actions
83 lines (78 loc) · 2.06 KB
/
EmailLinkView.swift
File metadata and controls
83 lines (78 loc) · 2.06 KB
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
83
import FirebaseAuth
import FirebaseCore
import SwiftUI
public struct EmailLinkView {
@Environment(AuthService.self) private var authService
@State private var email = ""
@State private var showModal = false
public init() {}
private func sendEmailLink() async {
do {
try await authService.sendEmailSignInLink(to: email)
showModal = true
} catch {}
}
}
extension EmailLinkView: View {
public var body: some View {
VStack {
Text("Sign in with email link")
LabeledContent {
TextField("Email", text: $email)
.textInputAutocapitalization(.never)
.disableAutocorrection(true)
.submitLabel(.next)
} label: {
Image(systemName: "at")
}.padding(.vertical, 6)
.background(Divider(), alignment: .bottom)
.padding(.bottom, 4)
Button(action: {
Task {
await sendEmailLink()
authService.emailLink = email
}
}) {
Text("Send email sign-in link")
.padding(.vertical, 8)
.frame(maxWidth: .infinity)
}
.disabled(!CommonUtils.isValidEmail(email))
.padding([.top, .bottom], 8)
.frame(maxWidth: .infinity)
.buttonStyle(.borderedProminent)
Text(authService.errorMessage).foregroundColor(.red)
}.sheet(isPresented: $showModal) {
VStack {
Text("Instructions")
.font(.headline)
Text("Please check your email for email sign-in link.")
.padding()
Button("Dismiss") {
showModal = false
}
.padding()
}
.padding()
}.onOpenURL { url in
Task {
do {
try await authService.handleSignInLink(url: url)
} catch {}
}
}
.navigationBarItems(leading: Button(action: {
authService.authView = .authPicker
}) {
Image(systemName: "chevron.left")
.foregroundColor(.blue)
Text("Back")
.foregroundColor(.blue)
})
}
}
#Preview {
FirebaseOptions.dummyConfigurationForPreview()
return EmailLinkView()
.environment(AuthService())
}