Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public final class AuthService {
private var listenerManager: AuthListenerManager?
private var signedInCredential: AuthCredential?

var emailSignInEnabled = false

private var providers: [ExternalAuthProvider] = []
public func register(provider: ExternalAuthProvider) {
providers.append(provider)
Expand Down Expand Up @@ -256,6 +258,11 @@ public extension AuthService {
// MARK: - Email/Password Sign In

public extension AuthService {
func withEmailSignIn() -> AuthService {
emailSignInEnabled = true
return self
}

func signIn(withEmail email: String, password: String) async throws {
let credential = EmailAuthProvider.credential(withEmail: email, password: password)
try await signIn(credentials: credential)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import FirebaseCore
import SwiftUI

@MainActor
public struct AuthPickerView<Content: View> {
public struct AuthPickerView {
@Environment(AuthService.self) private var authService
let providerButtons: () -> Content

public init(@ViewBuilder providerButtons: @escaping () -> Content) {
self.providerButtons = providerButtons
}
public init() {}

private func switchFlow() {
authService.authenticationFlow = authService
Expand All @@ -29,34 +27,43 @@ extension AuthPickerView: View {
} else if authService.authView == .emailLink {
EmailLinkView()
} else {
Text(authService.authenticationFlow == .login ? authService.string
.emailLoginFlowLabel : authService.string.emailSignUpFlowLabel)
VStack { Divider() }

EmailAuthView()
if authService.emailSignInEnabled {
Text(authService.authenticationFlow == .login ? authService.string
.emailLoginFlowLabel : authService.string.emailSignUpFlowLabel)
Divider()
EmailAuthView()
}
VStack {
authService.renderButtons()
}.padding(.horizontal)

VStack { Divider() }
HStack {
Text(authService
.authenticationFlow == .login ? authService.string.dontHaveAnAccountYetLabel :
authService.string.alreadyHaveAnAccountLabel)
Button(action: {
withAnimation {
switchFlow()
if authService.emailSignInEnabled {
Divider()
HStack {
Text(authService
.authenticationFlow == .login ? authService.string.dontHaveAnAccountYetLabel :
authService.string.alreadyHaveAnAccountLabel)
Button(action: {
withAnimation {
switchFlow()
}
}) {
Text(authService.authenticationFlow == .signUp ? authService.string
.emailLoginFlowLabel : authService.string.emailSignUpFlowLabel)
.fontWeight(.semibold)
.foregroundColor(.blue)
}
}) {
Text(authService.authenticationFlow == .signUp ? authService.string
.emailLoginFlowLabel : authService.string.emailSignUpFlowLabel)
.fontWeight(.semibold)
.foregroundColor(.blue)
}
PrivacyTOCsView(displayMode: .footer)
Text(authService.errorMessage).foregroundColor(.red)
}
PrivacyTOCsView(displayMode: .footer)
Text(authService.errorMessage).foregroundColor(.red)
}
}
}
}

#Preview {
FirebaseOptions.dummyConfigurationForPreview()
let authService = AuthService()
.withEmailSignIn()
return AuthPickerView().environment(authService)
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ extension EmailAuthView: View {
.frame(maxWidth: .infinity)
.buttonStyle(.borderedProminent)
Button(action: {
authService.authView = .passwordRecovery
authService.authView = .emailLink
}) {
Text(authService.string.signUpWithEmailLinkButtonLabel)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ struct ContentView: View {
.withGoogleSignIn()
.withFacebookSignIn()
.withPhoneSignIn()
.withEmailSignIn()
}

var body: some View {
AuthPickerView {
PhoneAuthButtonView()
}.environment(authService)
AuthPickerView().environment(authService)
}
}