-
Notifications
You must be signed in to change notification settings - Fork 490
Expand file tree
/
Copy pathAuthPickerView.swift
More file actions
51 lines (47 loc) · 1.46 KB
/
AuthPickerView.swift
File metadata and controls
51 lines (47 loc) · 1.46 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
import SwiftUI
@MainActor
public struct AuthPickerView<Content: View> {
@Environment(AuthService.self) private var authService
let providerButtons: () -> Content
public init(@ViewBuilder providerButtons: @escaping () -> Content) {
self.providerButtons = providerButtons
}
private func switchFlow() {
authService.authenticationFlow = authService
.authenticationFlow == .login ? .signUp : .login
}
}
extension AuthPickerView: View {
public var body: some View {
VStack {
if authService.authenticationState == .authenticated {
SignedInView()
} else if authService.authView == .passwordRecovery {
PasswordRecoveryView()
} else if authService.authView == .emailLink {
EmailLinkView()
} else {
Text(authService.authenticationFlow == .login ? "Login" : "Sign up")
VStack { Divider() }
EmailAuthView()
authService.renderButtons()
VStack { Divider() }
HStack {
Text(authService
.authenticationFlow == .login ? "Don't have an account yet?" :
"Already have an account?")
Button(action: {
withAnimation {
switchFlow()
}
}) {
Text(authService.authenticationFlow == .signUp ? "Log in" : "Sign up")
.fontWeight(.semibold)
.foregroundColor(.blue)
}
}
Text(authService.errorMessage).foregroundColor(.red)
}
}
}
}