From 1042f5f37127b47d0183c228e76db2895875b4bb Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Mon, 9 Dec 2024 15:25:08 -0800 Subject: [PATCH 1/2] [auth] Fix Multi-factor session crash on second Firebase app --- FirebaseAuth/CHANGELOG.md | 1 + FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift | 2 +- .../Sources/Swift/MultiFactor/MultiFactorSession.swift | 9 +++++++-- 3 files changed, 9 insertions(+), 3 deletions(-) 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..fdc53914180 100644 --- a/FirebaseAuth/Sources/Swift/MultiFactor/MultiFactorSession.swift +++ b/FirebaseAuth/Sources/Swift/MultiFactor/MultiFactorSession.swift @@ -39,8 +39,13 @@ 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 = if user != nil { + user + } else { + Auth.auth().currentUser + } + guard let currentUser else { fatalError("Internal Auth Error: missing user for multifactor auth") } return .init(idToken: currentUser.tokenService.accessToken, currentUser: currentUser) From 44a350bed64df40dd3ddd9b5b37f3df2920bdecb Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Tue, 10 Dec 2024 07:27:49 -0800 Subject: [PATCH 2/2] Update FirebaseAuth/Sources/Swift/MultiFactor/MultiFactorSession.swift Co-authored-by: Nick Cooke <36927374+ncooke3@users.noreply.github.com> --- .../Sources/Swift/MultiFactor/MultiFactorSession.swift | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/FirebaseAuth/Sources/Swift/MultiFactor/MultiFactorSession.swift b/FirebaseAuth/Sources/Swift/MultiFactor/MultiFactorSession.swift index fdc53914180..c4bda3eba36 100644 --- a/FirebaseAuth/Sources/Swift/MultiFactor/MultiFactorSession.swift +++ b/FirebaseAuth/Sources/Swift/MultiFactor/MultiFactorSession.swift @@ -40,11 +40,7 @@ import Foundation var currentUser: User? class func session(for user: User?) -> MultiFactorSession { - let currentUser = if user != nil { - user - } else { - Auth.auth().currentUser - } + let currentUser = user ?? Auth.auth().currentUser guard let currentUser else { fatalError("Internal Auth Error: missing user for multifactor auth") }