Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[auth-swift] Fix Component warning #12269

Merged
merged 2 commits into from
Jan 20, 2024
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
2 changes: 1 addition & 1 deletion FirebaseAuth/Sources/Swift/Auth/Auth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ extension Auth: AuthInterop {
@return The `Auth` instance associated with the given app.
*/
@objc open class func auth(app: FirebaseApp) -> Auth {
return ComponentType<AuthProvider>.instance(for: AuthProvider.self, in: app.container) as! Auth
return ComponentType<AuthProvider>.instance(for: AuthProvider.self, in: app.container).auth()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the type can be right here, since we return an AuthComponent instead of an Auth below.

}

/** @property app
Expand Down
7 changes: 5 additions & 2 deletions FirebaseAuth/Sources/Swift/Auth/AuthComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without doing this priming, User will not be initialized from the keychain

return newComponent
}]
}

// MARK: - AuthProvider conformance

func auth() -> Auth {
@discardableResult func auth() -> Auth {
os_unfair_lock_lock(&instancesLock)

// Unlock before the function returns.
Expand Down