diff --git a/FirebaseAuth/CHANGELOG.md b/FirebaseAuth/CHANGELOG.md index 9a878b35ca7..8940131c5c3 100644 --- a/FirebaseAuth/CHANGELOG.md +++ b/FirebaseAuth/CHANGELOG.md @@ -1,4 +1,5 @@ # Unreleased +- [fixed] Fix Multi-factor session crash on second Firebase app. (#14238) - [fixed] Updated most decoders to be consistent with Firebase 10's behavior for decoding `nil` values. (#14212) diff --git a/FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift b/FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift index c60f353e362..5b1675fdfa0 100644 --- a/FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift +++ b/FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift @@ -34,7 +34,7 @@ import Foundation /// operation. @objc(getSessionWithCompletion:) open func getSessionWithCompletion(_ completion: ((MultiFactorSession?, Error?) -> Void)?) { - let session = MultiFactorSession.sessionForCurrentUser + let session = MultiFactorSession.session(for: user) if let completion { completion(session, nil) } diff --git a/FirebaseAuth/Sources/Swift/MultiFactor/MultiFactorSession.swift b/FirebaseAuth/Sources/Swift/MultiFactor/MultiFactorSession.swift index 42067fd30c3..c4bda3eba36 100644 --- a/FirebaseAuth/Sources/Swift/MultiFactor/MultiFactorSession.swift +++ b/FirebaseAuth/Sources/Swift/MultiFactor/MultiFactorSession.swift @@ -39,8 +39,9 @@ import Foundation /// Current user object. var currentUser: User? - class var sessionForCurrentUser: MultiFactorSession { - guard let currentUser = Auth.auth().currentUser else { + class func session(for user: User?) -> MultiFactorSession { + let currentUser = user ?? Auth.auth().currentUser + guard let currentUser else { fatalError("Internal Auth Error: missing user for multifactor auth") } return .init(idToken: currentUser.tokenService.accessToken, currentUser: currentUser)