From 6b28c55aed472b10de058b455eec7483cae27b12 Mon Sep 17 00:00:00 2001 From: Stephane Peter Date: Sun, 3 May 2026 23:57:52 +0200 Subject: [PATCH 1/2] SignedInView: do not show MFA button when the project does not have it enabled. --- .../Sources/Views/SignedInView.swift | 30 +++++++++++------ .../SignedInViewTests.swift | 33 +++++++++++++++++++ 2 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 FirebaseSwiftUI/FirebaseAuthSwiftUI/Tests/FirebaseAuthSwiftUITests/SignedInViewTests.swift diff --git a/FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/SignedInView.swift b/FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/SignedInView.swift index cb886ddd0fa..fd6d4a91ba5 100644 --- a/FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/SignedInView.swift +++ b/FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/SignedInView.swift @@ -23,6 +23,14 @@ public struct SignedInView { @State private var showEmailVerificationSent = false @State private var reauthCoordinator = ReauthenticationCoordinator() + var showsMfaManagementButton: Bool { + Self.showsMfaManagementButton(configuration: authService.configuration) + } + + static func showsMfaManagementButton(configuration: AuthConfiguration) -> Bool { + configuration.mfaEnabled + } + private func sendEmailVerification() async throws { do { try await authService.sendEmailVerification() @@ -75,17 +83,19 @@ extension SignedInView: View { .frame(maxWidth: .infinity) .accessibilityIdentifier("update-password-button") - Button { - authService.navigator.push(.mfaManagement) - } label: { - Text(authService.string.manageTwoFactorAuthenticationLabel) - .padding(.vertical, 8) - .frame(maxWidth: .infinity) + if showsMfaManagementButton { + Button { + authService.navigator.push(.mfaManagement) + } label: { + Text(authService.string.manageTwoFactorAuthenticationLabel) + .padding(.vertical, 8) + .frame(maxWidth: .infinity) + } + .buttonStyle(.borderedProminent) + .padding([.top, .bottom], 8) + .frame(maxWidth: .infinity) + .accessibilityIdentifier("mfa-management-button") } - .buttonStyle(.borderedProminent) - .padding([.top, .bottom], 8) - .frame(maxWidth: .infinity) - .accessibilityIdentifier("mfa-management-button") Button { showDeleteConfirmation = true diff --git a/FirebaseSwiftUI/FirebaseAuthSwiftUI/Tests/FirebaseAuthSwiftUITests/SignedInViewTests.swift b/FirebaseSwiftUI/FirebaseAuthSwiftUI/Tests/FirebaseAuthSwiftUITests/SignedInViewTests.swift new file mode 100644 index 00000000000..b9cca5e44ef --- /dev/null +++ b/FirebaseSwiftUI/FirebaseAuthSwiftUI/Tests/FirebaseAuthSwiftUITests/SignedInViewTests.swift @@ -0,0 +1,33 @@ +// 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 + +@Suite("SignedInView Tests") +struct SignedInViewTests { + @Test("MFA management button is hidden when MFA is disabled") + func mfaManagementButtonHiddenWhenMfaDisabled() { + let configuration = AuthConfiguration(mfaEnabled: false) + + #expect(SignedInView.showsMfaManagementButton(configuration: configuration) == false) + } + + @Test("MFA management button is shown when MFA is enabled") + func mfaManagementButtonShownWhenMfaEnabled() { + let configuration = AuthConfiguration(mfaEnabled: true) + + #expect(SignedInView.showsMfaManagementButton(configuration: configuration) == true) + } +} From 0c593f1d8682b379c42f53a66183e81d2fb47d98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Peter?= Date: Mon, 4 May 2026 12:12:31 +0200 Subject: [PATCH 2/2] Update FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/SignedInView.swift Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- .../FirebaseAuthSwiftUI/Sources/Views/SignedInView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/SignedInView.swift b/FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/SignedInView.swift index fd6d4a91ba5..61ad1cd10a1 100644 --- a/FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/SignedInView.swift +++ b/FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/SignedInView.swift @@ -23,7 +23,7 @@ public struct SignedInView { @State private var showEmailVerificationSent = false @State private var reauthCoordinator = ReauthenticationCoordinator() - var showsMfaManagementButton: Bool { + private var showsMfaManagementButton: Bool { Self.showsMfaManagementButton(configuration: authService.configuration) }