Skip to content

Commit

Permalink
Make sure currentUser is available upon startup
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Feb 4, 2025
1 parent 5dd57f9 commit d4208a3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
9 changes: 4 additions & 5 deletions Sources/SpeziFirebaseAccount/FirebaseAccountService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d4208a3

Please sign in to comment.