From b47e629e0bb3147a69d5a92e75c4cb7db496ef7e Mon Sep 17 00:00:00 2001 From: Ademola Fadumo <48495111+demolaf@users.noreply.github.com> Date: Wed, 18 Nov 2026 15:04:10 +0100 Subject: [PATCH 1/2] fix(auth): close sign-in screens once the user is signed in --- .../Sources/Services/AuthService.swift | 22 +++++++-- .../Sources/Views/AuthPickerContent.swift | 6 +-- .../NavigatorTests.swift | 46 +++++++++++++++++++ 3 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 FirebaseSwiftUI/FirebaseAuthSwiftUI/Tests/FirebaseAuthSwiftUITests/NavigatorTests.swift diff --git a/FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Services/AuthService.swift b/FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Services/AuthService.swift index 0e0a6839f0..1e29c11d17 100644 --- a/FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Services/AuthService.swift +++ b/FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Services/AuthService.swift @@ -91,6 +91,19 @@ public enum AuthView: Hashable { case enterVerificationCode(verificationID: String, fullPhoneNumber: String) } +extension AuthView { + /// Whether the screen is part of signing in, so it is done once the user is signed in. + var isSignedOutOnly: Bool { + switch self { + case .signIn, .signUp, .emailLink, .passwordRecovery, .enterPhoneNumber, + .enterVerificationCode, .mfaResolution: + true + case .updatePassword, .mfaEnrollment, .mfaManagement: + false + } + } +} + public enum SignInOutcome: @unchecked Sendable { case mfaRequired(MFARequired) case signedIn(AuthDataResult?) @@ -169,10 +182,11 @@ public class Navigator { routes.removeAll() } - /// Removes pushed ``AuthView/signIn`` and ``AuthView/signUp`` screens, which have nothing left - /// to do once the user is signed in. - func removeEmailRoutes() { - routes.removeAll { $0 == .signIn || $0 == .signUp } + /// Removes pushed screens that only apply while signed out, such as sign-in, email link and + /// phone verification, which have nothing left to do once the user is signed in. Screens for + /// a signed-in user, such as MFA management, stay. + func removeSignedOutRoutes() { + routes.removeAll(where: \.isSignedOutOnly) } /// Leaves a pushed ``AuthView/signUp`` screen for sign-in: back to the sign-in screen under diff --git a/FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/AuthPickerContent.swift b/FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/AuthPickerContent.swift index 69b9c92a9e..6400c6ebd9 100644 --- a/FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/AuthPickerContent.swift +++ b/FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/AuthPickerContent.swift @@ -98,11 +98,11 @@ public struct AuthPickerContent< .environment(authService) } .interactiveDismissDisabled(authService.configuration.interactiveDismissEnabled) - // Close pushed email screens however the user got signed in, including account - // conflicts the library resolves by signing in for them. + // Close pushed sign-in screens however the user got signed in, including email links + // and account conflicts the library resolves by signing in for them. .onChange(of: authService.authenticationState) { _, state in if state == .authenticated { - authService.navigator.removeEmailRoutes() + authService.navigator.removeSignedOutRoutes() } } // Apply account conflict handling at NavigationStack level diff --git a/FirebaseSwiftUI/FirebaseAuthSwiftUI/Tests/FirebaseAuthSwiftUITests/NavigatorTests.swift b/FirebaseSwiftUI/FirebaseAuthSwiftUI/Tests/FirebaseAuthSwiftUITests/NavigatorTests.swift new file mode 100644 index 0000000000..8658bd72ef --- /dev/null +++ b/FirebaseSwiftUI/FirebaseAuthSwiftUI/Tests/FirebaseAuthSwiftUITests/NavigatorTests.swift @@ -0,0 +1,46 @@ +// Copyright 2025 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +@testable import FirebaseAuthSwiftUI +import Testing + +struct NavigatorTests { + @Test("Signing in removes every signed-out screen, including the email link screen") + func removesSignedOutRoutes() { + let navigator = Navigator() + navigator.routes = [ + .signIn, + .signUp, + .emailLink, + .passwordRecovery, + .enterPhoneNumber, + .enterVerificationCode(verificationID: "id", fullPhoneNumber: "+15551234567"), + .mfaResolution(MFARequired(hints: [.totp(displayName: nil, uid: "uid")])), + ] + + navigator.removeSignedOutRoutes() + + #expect(navigator.routes.isEmpty) + } + + @Test("Signing in keeps screens for a signed-in user, in order") + func keepsSignedInRoutes() { + let navigator = Navigator() + navigator.routes = [.mfaManagement, .emailLink, .mfaEnrollment, .updatePassword] + + navigator.removeSignedOutRoutes() + + #expect(navigator.routes == [.mfaManagement, .mfaEnrollment, .updatePassword]) + } +} From 631cc5d28952d678f21e1926881c5644c25f1af1 Mon Sep 17 00:00:00 2001 From: Ademola Fadumo <48495111+demolaf@users.noreply.github.com> Date: Wed, 18 Nov 2026 15:42:46 +0100 Subject: [PATCH 2/2] test(auth): move the signed-out route tests into EmailRouteTests --- .../NavigatorTests.swift | 46 ------------------- .../EmailRouteTests.swift | 28 ++++++++--- 2 files changed, 22 insertions(+), 52 deletions(-) delete mode 100644 FirebaseSwiftUI/FirebaseAuthSwiftUI/Tests/FirebaseAuthSwiftUITests/NavigatorTests.swift diff --git a/FirebaseSwiftUI/FirebaseAuthSwiftUI/Tests/FirebaseAuthSwiftUITests/NavigatorTests.swift b/FirebaseSwiftUI/FirebaseAuthSwiftUI/Tests/FirebaseAuthSwiftUITests/NavigatorTests.swift deleted file mode 100644 index 8658bd72ef..0000000000 --- a/FirebaseSwiftUI/FirebaseAuthSwiftUI/Tests/FirebaseAuthSwiftUITests/NavigatorTests.swift +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2025 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -@testable import FirebaseAuthSwiftUI -import Testing - -struct NavigatorTests { - @Test("Signing in removes every signed-out screen, including the email link screen") - func removesSignedOutRoutes() { - let navigator = Navigator() - navigator.routes = [ - .signIn, - .signUp, - .emailLink, - .passwordRecovery, - .enterPhoneNumber, - .enterVerificationCode(verificationID: "id", fullPhoneNumber: "+15551234567"), - .mfaResolution(MFARequired(hints: [.totp(displayName: nil, uid: "uid")])), - ] - - navigator.removeSignedOutRoutes() - - #expect(navigator.routes.isEmpty) - } - - @Test("Signing in keeps screens for a signed-in user, in order") - func keepsSignedInRoutes() { - let navigator = Navigator() - navigator.routes = [.mfaManagement, .emailLink, .mfaEnrollment, .updatePassword] - - navigator.removeSignedOutRoutes() - - #expect(navigator.routes == [.mfaManagement, .mfaEnrollment, .updatePassword]) - } -} diff --git a/e2eTest/FirebaseSwiftUIExample/FirebaseSwiftUIExampleTests/EmailRouteTests.swift b/e2eTest/FirebaseSwiftUIExample/FirebaseSwiftUIExampleTests/EmailRouteTests.swift index 0aaed10e9c..9b1d0f3756 100644 --- a/e2eTest/FirebaseSwiftUIExample/FirebaseSwiftUIExampleTests/EmailRouteTests.swift +++ b/e2eTest/FirebaseSwiftUIExample/FirebaseSwiftUIExampleTests/EmailRouteTests.swift @@ -26,15 +26,31 @@ struct EmailRouteTests { private let emailOption = LegacySignInOption(id: EmailAuthProviderID, displayName: "Email") @Test - func removeEmailRoutesKeepsOtherRoutes() { + func removeSignedOutRoutesRemovesEverySignInScreen() { let navigator = Navigator() - navigator.push(.signIn) - navigator.push(.signUp) - navigator.push(.passwordRecovery) + navigator.routes = [ + .signIn, + .signUp, + .emailLink, + .passwordRecovery, + .enterPhoneNumber, + .enterVerificationCode(verificationID: "id", fullPhoneNumber: "+15551234567"), + .mfaResolution(MFARequired(hints: [.totp(displayName: nil, uid: "uid")])), + ] + + navigator.removeSignedOutRoutes() + + #expect(navigator.routes.isEmpty) + } - navigator.removeEmailRoutes() + @Test + func removeSignedOutRoutesKeepsSignedInScreensInOrder() { + let navigator = Navigator() + navigator.routes = [.mfaManagement, .emailLink, .mfaEnrollment, .updatePassword] - #expect(navigator.routes == [.passwordRecovery]) + navigator.removeSignedOutRoutes() + + #expect(navigator.routes == [.mfaManagement, .mfaEnrollment, .updatePassword]) } @Test