Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Expand Up @@ -308,12 +308,14 @@ public class StringUtils {
public var enterPhoneNumberLabel: String {
return localizedString(for: "Enter phone number")
}

/// Phone provider
/// found in:
/// - PhoneAuthButtonView
public var phoneNumberVerificationCodeLabel: String {
return localizedString(for: "Enter verification code")
}

/// Phone provider
/// found in:
/// - PhoneAuthButtonView
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
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,28 +26,32 @@ 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)
VStack { Divider() }
EmailAuthView()
}
authService.renderButtons()
VStack { Divider() }
HStack {
Text(authService
.authenticationFlow == .login ? authService.string.dontHaveAnAccountYetLabel :
authService.string.alreadyHaveAnAccountLabel)
Button(action: {
withAnimation {
switchFlow()
if authService.emailSignInEnabled {
VStack { 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)
}
Text(authService.errorMessage).foregroundColor(.red)
}
Text(authService.errorMessage).foregroundColor(.red)
}
}
}
Expand Down
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 @@ -34,11 +34,10 @@ struct ContentView: View {
.withGoogleSignIn()
.withFacebookSignIn()
.withPhoneSignIn()
.withEmailSignIn()
}

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