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 @@ -29,7 +29,7 @@ public struct SignInWithAppleButton {
extension SignInWithAppleButton: View {
public var body: some View {
AuthProviderButton(
label: "Sign in with Apple",
label: authService.string.appleLoginButtonLabel,
style: .apple,
accessibilityId: "sign-in-with-apple-button"
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@

import FirebaseAuth
import Foundation
import SwiftUI

public struct AuthConfiguration {
public let logo: ImageResource?
public let languageCode: String?
public let shouldHideCancelButton: Bool
public let interactiveDismissEnabled: Bool
public let shouldAutoUpgradeAnonymousUsers: Bool
Expand All @@ -31,21 +34,27 @@ public struct AuthConfiguration {
public let allowedSecondFactors: Set<SecondFactorType>
public let mfaIssuer: String

public init(shouldHideCancelButton: Bool = false,
interactiveDismissEnabled: Bool = true,
shouldAutoUpgradeAnonymousUsers: Bool = false,
customStringsBundle: Bundle? = nil,
tosUrl: URL? = nil,
privacyPolicyUrl: URL? = nil,
emailLinkSignInActionCodeSettings: ActionCodeSettings? = nil,
verifyEmailActionCodeSettings: ActionCodeSettings? = nil,
mfaEnabled: Bool = false,
allowedSecondFactors: Set<SecondFactorType> = [.sms, .totp],
mfaIssuer: String = "Firebase Auth") {
public init(
logo: ImageResource? = nil,
languageCode: String? = nil,
shouldHideCancelButton: Bool = false,
interactiveDismissEnabled: Bool = true,
shouldAutoUpgradeAnonymousUsers: Bool = false,
customStringsBundle: Bundle? = nil,
tosUrl: URL? = nil,
privacyPolicyUrl: URL? = nil,
emailLinkSignInActionCodeSettings: ActionCodeSettings? = nil,
verifyEmailActionCodeSettings: ActionCodeSettings? = nil,
mfaEnabled: Bool = false,
allowedSecondFactors: Set<SecondFactorType> = [.sms, .totp],
mfaIssuer: String = "Firebase Auth"
) {
self.logo = logo
self.shouldHideCancelButton = shouldHideCancelButton
self.interactiveDismissEnabled = interactiveDismissEnabled
self.shouldAutoUpgradeAnonymousUsers = shouldAutoUpgradeAnonymousUsers
self.customStringsBundle = customStringsBundle
self.languageCode = languageCode
self.tosUrl = tosUrl
self.privacyPolicyUrl = privacyPolicyUrl
self.emailLinkSignInActionCodeSettings = emailLinkSignInActionCodeSettings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ public protocol AuthProviderUI {
var provider: AuthProviderSwift { get }
}

public protocol PhoneAuthProviderSwift: AuthProviderSwift, AnyObject {
// Phone auth provider that presents its own UI flow in createAuthCredential()
// Internal use only: AuthService will be injected automatically by AuthService.signIn()
var authService: AuthService? { get set }
public protocol PhoneAuthProviderSwift: AuthProviderSwift {
@MainActor func verifyPhoneNumber(phoneNumber: String) async throws -> String
@MainActor func createAuthCredential(verificationId: String, verificationCode: String) async throws -> AuthCredential
}

public enum AuthenticationState {
Expand All @@ -51,6 +50,8 @@ public enum AuthView: Hashable {
case mfaEnrollment
case mfaManagement
case mfaResolution
case enterPhoneNumber
case enterVerificationCode(verificationID: String, fullPhoneNumber: String)
}

public enum SignInOutcome: @unchecked Sendable {
Expand Down Expand Up @@ -108,7 +109,7 @@ public final class AuthService {
public init(configuration: AuthConfiguration = AuthConfiguration(), auth: Auth = Auth.auth()) {
self.auth = auth
self.configuration = configuration
string = StringUtils(bundle: configuration.customStringsBundle ?? Bundle.module)
string = StringUtils(bundle: configuration.customStringsBundle ?? Bundle.module, languageCode: configuration.languageCode)
listenerManager = AuthListenerManager(auth: auth, authEnvironment: self)
FirebaseApp.registerLibrary("firebase-ui-ios", withVersion: FirebaseAuthSwiftUIVersion.version)
}
Expand Down Expand Up @@ -159,6 +160,10 @@ public final class AuthService {

private var providers: [AuthProviderUI] = []

public var currentPhoneProvider: PhoneAuthProviderSwift? {
providers.compactMap { $0.provider as? PhoneAuthProviderSwift }.first
}

public func registerProvider(providerWithButton: AuthProviderUI) {
providers.append(providerWithButton)
}
Expand All @@ -182,11 +187,6 @@ public final class AuthService {

public func signIn(_ provider: AuthProviderSwift) async throws -> SignInOutcome {
do {
// Automatically inject AuthService for phone provider
if let phoneProvider = provider as? PhoneAuthProviderSwift {
phoneProvider.authService = self
}

let credential = try await provider.createAuthCredential()
let result = try await signIn(credentials: credential)
return result
Expand Down
Loading
Loading