-
Notifications
You must be signed in to change notification settings - Fork 481
/
Copy pathAuthPickerView.swift
46 lines (42 loc) · 1.23 KB
/
AuthPickerView.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
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 {
Text(authService.authenticationFlow == .login ? "Login" : "Sign up")
VStack { Divider() }
EmailAuthView()
providerButtons()
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)
}
}
}
}
}
}