Skip to content

Commit b15292c

Browse files
update email provider to pass authEnv and to use auth instance
1 parent d85fda4 commit b15292c

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public enum AuthenticationFlow {
2828
public final class AuthEnvironment {
2929
public static let shared = AuthEnvironment()
3030

31+
// TODO: - need to know how we're configuring the below properties or if they should live on AuthEnvironment
32+
let auth: Auth = .auth()
33+
let language: String = "en"
34+
let enableAutoAnonymousLogin: Bool = true
35+
3136
var currentUser: User?
3237
var errorMessage = ""
3338

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/FirebaseAuthSwiftUI/Services/EmailProvider.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ import SwiftUI
33

44
@MainActor
55
public class EmailAuthProvider {
6-
@Environment(AuthEnvironment.self) private var authEnvironment
6+
private let authEnvironment: AuthEnvironment
77

8-
public init() {}
8+
public init(authEnvironment: AuthEnvironment) {
9+
self.authEnvironment = authEnvironment
10+
}
911

1012
func signIn(withEmail email: String, password: String) async throws {
1113
authEnvironment.authenticationState = .authenticating
1214
do {
13-
try await Auth.auth().createUser(withEmail: email, password: password)
15+
try await authEnvironment.auth.createUser(withEmail: email, password: password)
1416
} catch {
1517
authEnvironment.authenticationState = .unauthenticated
1618
throw error
@@ -20,7 +22,7 @@ public class EmailAuthProvider {
2022
func signUp(withEmail email: String, password: String) async throws {
2123
authEnvironment.authenticationState = .authenticating
2224
do {
23-
try await Auth.auth().createUser(withEmail: email, password: password)
25+
try await authEnvironment.auth.createUser(withEmail: email, password: password)
2426
} catch {
2527
authEnvironment.authenticationState = .unauthenticated
2628
throw error

0 commit comments

Comments
 (0)