Skip to content

Commit 712f75f

Browse files
chore: create AuthConfiguration and adjust
1 parent 7d7a039 commit 712f75f

3 files changed

Lines changed: 35 additions & 12 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Foundation
2+
3+
public final class AuthConfiguration {
4+
var shouldHideCancelButton: Bool
5+
var interactiveDismissEnabled: Bool
6+
var shouldAutoUpgradeAnonymousUsers: Bool
7+
var customStringsBundle: Bundle
8+
var tosUrl: URL
9+
var privacyPolicyUrl: URL
10+
11+
public init(shouldHideCancelButton: Bool = false,
12+
interactiveDismissEnabled: Bool = true,
13+
shouldAutoUpgradeAnonymousUsers: Bool = false,
14+
customStringsBundle: Bundle = Bundle.main,
15+
tosUrl: URL = URL(string: "https://example.com/tos")!,
16+
privacyPolicyUrl: URL = URL(string: "https://example.com/privacy")!) {
17+
self.shouldHideCancelButton = shouldHideCancelButton
18+
self.interactiveDismissEnabled = interactiveDismissEnabled
19+
self.shouldAutoUpgradeAnonymousUsers = shouldAutoUpgradeAnonymousUsers
20+
self.customStringsBundle = customStringsBundle
21+
self.tosUrl = tosUrl
22+
self.privacyPolicyUrl = privacyPolicyUrl
23+
}
24+
}

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/FirebaseAuthSwiftUI/Services/AuthEnvironment.swift

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,18 @@ final class AuthListenerManager {
5252
@MainActor
5353
@Observable
5454
public final class AuthEnvironment {
55-
public static let shared = AuthEnvironment()
56-
57-
// TODO: - need to know how we're configuring the below properties or if they should live on AuthEnvironment
58-
let auth: Auth = .auth()
59-
let language: String = "en"
60-
let enableAutoAnonymousLogin: Bool = true
61-
62-
var currentUser: User?
63-
var errorMessage = ""
64-
55+
public let configuation: AuthConfiguration
56+
public let auth: Auth
6557
private var listenerManager: AuthListenerManager?
6658

67-
private init() {
59+
public init(configuration: AuthConfiguration = AuthConfiguration(), auth: Auth = Auth.auth()) {
60+
self.auth = auth
61+
configuation = configuration
6862
listenerManager = AuthListenerManager(auth: auth, authEnvironment: self)
6963
}
7064

65+
public var currentUser: User?
66+
public var errorMessage = ""
7167
public var authenticationState: AuthenticationState = .unauthenticated
7268
public var authenticationFlow: AuthenticationFlow = .login
7369

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExample/FirebaseSwiftUIExampleApp.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ import SwiftUI
1515
struct FirebaseSwiftUIExampleApp: App {
1616
init() {
1717
FirebaseApp.configure()
18+
authViewModel = AuthEnvironment()
1819
}
1920

21+
let authViewModel: AuthEnvironment
22+
2023
var body: some Scene {
2124
WindowGroup {
2225
NavigationView {
23-
AuthenticationScreen().environment(AuthEnvironment.shared)
26+
AuthenticationScreen().environment(authViewModel)
2427
}
2528
}
2629
}

0 commit comments

Comments
 (0)