From 998853a9194d23ce41055ba555f6f6eb70bad6cd Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Sat, 13 Jan 2024 08:12:24 -0800 Subject: [PATCH] Component cleanup --- FirebaseAuth/Sources/Swift/Auth/Auth.swift | 9 +-------- FirebaseAuth/Sources/Swift/Auth/AuthComponent.swift | 7 +++++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/FirebaseAuth/Sources/Swift/Auth/Auth.swift b/FirebaseAuth/Sources/Swift/Auth/Auth.swift index c427b303410..d45fb5f65f9 100644 --- a/FirebaseAuth/Sources/Swift/Auth/Auth.swift +++ b/FirebaseAuth/Sources/Swift/Auth/Auth.swift @@ -139,13 +139,6 @@ extension Auth: AuthInterop { } } -// This prevents FIRComponentContainer from warning when instantiating from the protocol. -extension Auth: AuthProvider { - func auth() -> Auth { - return self - } -} - /** @class Auth @brief Manages authentication for Firebase apps. @remarks This class is thread-safe. @@ -175,7 +168,7 @@ extension Auth: AuthProvider { @return The `Auth` instance associated with the given app. */ @objc open class func auth(app: FirebaseApp) -> Auth { - return ComponentType.instance(for: AuthProvider.self, in: app.container) as! Auth + return ComponentType.instance(for: AuthProvider.self, in: app.container).auth() } /** @property app diff --git a/FirebaseAuth/Sources/Swift/Auth/AuthComponent.swift b/FirebaseAuth/Sources/Swift/Auth/AuthComponent.swift index f0be914d6a6..277fcce76b1 100644 --- a/FirebaseAuth/Sources/Swift/Auth/AuthComponent.swift +++ b/FirebaseAuth/Sources/Swift/Auth/AuthComponent.swift @@ -53,13 +53,16 @@ class AuthComponent: NSObject, Library, AuthProvider, ComponentLifecycleMaintain dependencies: [appCheckInterop]) { container, isCacheable in guard let app = container.app else { return nil } isCacheable.pointee = true - return Auth(app: app) + let newComponent = AuthComponent(app: app) + // Set up instances early enough so User on keychain will be decoded. + newComponent.auth() + return newComponent }] } // MARK: - AuthProvider conformance - func auth() -> Auth { + @discardableResult func auth() -> Auth { os_unfair_lock_lock(&instancesLock) // Unlock before the function returns.