From d4208a3504e455ce15ee5ab0c64ab5b77b3a3050 Mon Sep 17 00:00:00 2001 From: Andreas Bauer Date: Tue, 4 Feb 2025 21:50:23 +0100 Subject: [PATCH] Make sure currentUser is available upon startup --- Package.swift | 2 +- .../SpeziFirebaseAccount/FirebaseAccountService.swift | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Package.swift b/Package.swift index 1ee51c9..cd54027 100644 --- a/Package.swift +++ b/Package.swift @@ -30,7 +30,7 @@ let package = Package( .package(url: "https://github.com/StanfordSpezi/Spezi", from: "1.7.1"), .package(url: "https://github.com/StanfordSpezi/SpeziViews", from: "1.6.0"), .package(url: "https://github.com/StanfordSpezi/SpeziAccount", from: "2.1.1"), - .package(url: "https://github.com/firebase/firebase-ios-sdk", from: "11.0.0"), + .package(url: "https://github.com/firebase/firebase-ios-sdk", from: "11.8.0"), .package(url: "https://github.com/apple/swift-atomics.git", from: "1.2.0") ] + swiftLintPackage(), targets: [ diff --git a/Sources/SpeziFirebaseAccount/FirebaseAccountService.swift b/Sources/SpeziFirebaseAccount/FirebaseAccountService.swift index 798d21c..20ddda7 100644 --- a/Sources/SpeziFirebaseAccount/FirebaseAccountService.swift +++ b/Sources/SpeziFirebaseAccount/FirebaseAccountService.swift @@ -247,11 +247,10 @@ public final class FirebaseAccountService: AccountService { // swiftlint:disable } } - // The `Auth.auth().currentUser` is not available immediately. The init of `Auth` delays - // the retrieval of the keychain object. - // See https://github.com/firebase/firebase-ios-sdk/blob/main/FirebaseAuth/Sources/Swift/Auth/Auth.swift#L1646. - // To increase our chance that the initial check did run, we move this check to the end. - // Every call to Auth.auth() acquires a lock, so this might increase our chance that the initialization did complete successfully. + // Firebase v11.6.0 restore the v10 behavior where the currentUser is available immediately after startup. + // `currentUser` will sync to the Auth worker queue, see https://github.com/firebase/firebase-ios-sdk/pull/14141. + // The Auth.init kicked off loading the current user already above, so we might not need to wait that long here. + // But, if there is a user, it will definitely get loaded here. checkForInitialUserAccount() Task.detached { [logger, secureStorage, localStorage] in