Repository navigation
feat(auth): add content slots to the reauthentication prompts #1423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // 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. | ||
|
|
||
| import FirebaseAuthUIComponents | ||
| import SwiftUI | ||
|
|
||
| /// The stock content of ``EmailLinkReauthScreen``. | ||
| @MainActor | ||
| public struct DefaultEmailLinkReauthContent: View { | ||
| public init(state: EmailLinkReauthContentState) { | ||
| self.state = state | ||
| } | ||
|
|
||
| private let state: EmailLinkReauthContentState | ||
|
|
||
| public var body: some View { | ||
| VStack(spacing: 24) { | ||
| if state.linkSent { | ||
| // "Check your email" state | ||
| VStack(spacing: 16) { | ||
| Image(systemName: "envelope.open.fill") | ||
| .font(.system(size: 60)) | ||
| .foregroundColor(.accentColor) | ||
| .padding(.top, 32) | ||
|
|
||
| Text("Check Your Email") | ||
| .authFont(.title) | ||
| .fontWeight(.bold) | ||
|
|
||
| Text("We've sent a verification link to:") | ||
| .authFont(.body) | ||
| .foregroundStyle(.secondary) | ||
|
|
||
| Text(state.email) | ||
| .authFont(.body) | ||
| .fontWeight(.medium) | ||
| .padding(.horizontal) | ||
|
|
||
| Text("Tap the link in the email to complete reauthentication.") | ||
| .authFont(.body) | ||
| .multilineTextAlignment(.center) | ||
| .foregroundStyle(.secondary) | ||
| .padding(.horizontal, 32) | ||
| .padding(.top, 8) | ||
|
|
||
| Button(action: state.resendLink) { | ||
| if state.isLoading { | ||
| ProgressView() | ||
| .frame(height: 32) | ||
| } else { | ||
| Text("Resend Email") | ||
| .authCustomFont(.body) | ||
| .frame(height: 32) | ||
| } | ||
| } | ||
| .buttonStyle(.bordered) | ||
| .disabled(state.isLoading) | ||
| .padding(.top, 16) | ||
| } | ||
| } else { | ||
| // Loading/sending state | ||
| VStack(spacing: 16) { | ||
| ProgressView() | ||
| .padding(.top, 32) | ||
| Text("Sending verification email...") | ||
| .authCustomFont(.body) | ||
| .foregroundStyle(.secondary) | ||
| } | ||
| } | ||
|
|
||
| Spacer() | ||
| } | ||
| .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top) | ||
| .navigationTitle("Verify Your Identity") | ||
| .navigationBarTitleDisplayMode(.inline) | ||
| .toolbar { | ||
| ToolbarItem(placement: .cancellationAction) { | ||
| Button("Cancel", action: state.cancel) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // 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. | ||
|
|
||
| import FirebaseAuthUIComponents | ||
| import SwiftUI | ||
|
|
||
| /// The stock content of ``EmailReauthScreen``. | ||
| @MainActor | ||
| public struct DefaultEmailReauthContent: View { | ||
| public init(state: EmailReauthContentState) { | ||
| self.state = state | ||
| } | ||
|
|
||
| @Environment(AuthService.self) private var authService | ||
| private let state: EmailReauthContentState | ||
|
|
||
| public var body: some View { | ||
| VStack(spacing: 24) { | ||
| // Header | ||
| VStack(spacing: 12) { | ||
| Image(systemName: "lock.circle.fill") | ||
| .font(.system(size: 60)) | ||
| .foregroundColor(.blue) | ||
|
Comment on lines
+32
to
+34
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| Text(authService.string.confirmPasswordTitle) | ||
| .authFont(.title) | ||
| .fontWeight(.bold) | ||
|
|
||
| Text(authService.string.forSecurityEnterPasswordMessage) | ||
| .authFont(.body) | ||
| .foregroundColor(.secondary) | ||
|
Comment on lines
+40
to
+42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| .multilineTextAlignment(.center) | ||
| } | ||
| .padding() | ||
|
|
||
| VStack(spacing: 20) { | ||
| Text(authService.string.emailPrefix(email: state.email)) | ||
| .authFont(.caption) | ||
| .frame(maxWidth: .infinity, alignment: .leading) | ||
| .padding(.bottom, 8) | ||
|
|
||
| AuthTextField( | ||
| text: state.password, | ||
| label: authService.string.passwordFieldLabel, | ||
| prompt: authService.string.passwordInputLabel, | ||
| contentType: .password, | ||
| isSecureTextField: true, | ||
| onSubmit: { _ in | ||
| state.verify() | ||
| }, | ||
| leading: { | ||
| Image(systemName: "lock") | ||
| } | ||
| ) | ||
| .submitLabel(.done) | ||
| .accessibilityIdentifier("email-reauth-password-field") | ||
|
|
||
| Button(action: state.verify) { | ||
| if state.isLoading { | ||
| ProgressView() | ||
| .frame(height: 32) | ||
| .frame(maxWidth: .infinity) | ||
| } else { | ||
| Text(authService.string.confirmButtonLabel) | ||
| .frame(height: 32) | ||
| .frame(maxWidth: .infinity) | ||
| } | ||
| } | ||
| .authCTAButtonStyle() | ||
| .disabled(!state.isValid || state.isLoading) | ||
| .accessibilityIdentifier("confirm-password-button") | ||
|
|
||
| Button(authService.string.cancelButtonLabel, action: state.cancel) | ||
| } | ||
| .padding(.horizontal) | ||
|
|
||
| Spacer() | ||
| } | ||
| .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top) | ||
| .navigationBarTitleDisplayMode(.inline) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| // 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. | ||
|
|
||
| import FirebaseAuthUIComponents | ||
| import SwiftUI | ||
|
|
||
| /// The stock content of ``PhoneReauthScreen``. | ||
| @MainActor | ||
| public struct DefaultPhoneReauthContent: View { | ||
| public init(state: PhoneReauthContentState) { | ||
| self.state = state | ||
| } | ||
|
|
||
| @Environment(AuthService.self) private var authService | ||
| private let state: PhoneReauthContentState | ||
|
|
||
| public var body: some View { | ||
| VStack(spacing: 24) { | ||
| // Header | ||
| VStack(spacing: 12) { | ||
| Image(systemName: "phone.circle.fill") | ||
| .font(.system(size: 60)) | ||
| .foregroundColor(.blue) | ||
|
Comment on lines
+32
to
+34
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| Text(authService.string.verifyPhoneNumberTitle) | ||
| .authFont(.title) | ||
| .fontWeight(.bold) | ||
|
|
||
| Text(authService.string.forSecurityVerifyPhoneMessage) | ||
| .authFont(.body) | ||
| .foregroundColor(.secondary) | ||
|
Comment on lines
+40
to
+42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| .multilineTextAlignment(.center) | ||
| } | ||
| .padding() | ||
|
|
||
| if !state.codeSent { | ||
| // Initial state - sending SMS | ||
| VStack(spacing: 20) { | ||
| Text(authService.string.sendVerificationCodeToPhonePrefix) | ||
| .authFont(.subheadline) | ||
| .foregroundStyle(.secondary) | ||
| .frame(maxWidth: .infinity, alignment: .leading) | ||
|
|
||
| Text(state.phoneNumber) | ||
| .authFont(.headline) | ||
| .frame(maxWidth: .infinity, alignment: .leading) | ||
| .padding(.bottom, 8) | ||
|
|
||
| Button(action: state.sendCode) { | ||
| if state.isLoading { | ||
| ProgressView() | ||
| .frame(height: 32) | ||
| .frame(maxWidth: .infinity) | ||
| } else { | ||
| Text(authService.string.sendVerificationCodeButtonLabel) | ||
| .frame(height: 32) | ||
| .frame(maxWidth: .infinity) | ||
| } | ||
| } | ||
| .authCTAButtonStyle() | ||
| .disabled(state.isLoading) | ||
| .accessibilityIdentifier("send-verification-code-button") | ||
| Button(authService.string.cancelButtonLabel, action: state.cancel) | ||
| } | ||
| .padding(.horizontal) | ||
| } else { | ||
| // Enter verification code | ||
| VStack(spacing: 20) { | ||
| Text(authService.string.enterSixDigitCodeSentToPrefix) | ||
| .authFont(.subheadline) | ||
| .foregroundStyle(.secondary) | ||
| .frame(maxWidth: .infinity, alignment: .leading) | ||
|
|
||
| Text(state.phoneNumber) | ||
| .authFont(.caption) | ||
| .frame(maxWidth: .infinity, alignment: .leading) | ||
| .padding(.bottom, 8) | ||
|
|
||
| VerificationCodeInputField( | ||
| code: state.verificationCode, | ||
| validations: [ | ||
| FormValidators.verificationCode, | ||
| ], | ||
| maintainsValidationMessage: true | ||
| ) | ||
| .accessibilityIdentifier("verification-code-field") | ||
|
|
||
| Button(action: state.verify) { | ||
| if state.isLoading { | ||
| ProgressView() | ||
| .frame(height: 32) | ||
| .frame(maxWidth: .infinity) | ||
| } else { | ||
| Text(authService.string.verifyButtonLabel) | ||
| .frame(height: 32) | ||
| .frame(maxWidth: .infinity) | ||
| } | ||
| } | ||
| .authCTAButtonStyle() | ||
| .disabled(!state.isValid || state.isLoading) | ||
| .accessibilityIdentifier("verify-button") | ||
|
|
||
| Button(action: state.sendCode) { | ||
| Text("Resend Code") | ||
| .frame(height: 32) | ||
| .frame(maxWidth: .infinity) | ||
| } | ||
| .buttonStyle(.bordered) | ||
| .disabled(state.isLoading) | ||
| .accessibilityIdentifier("resend-code-button") | ||
|
|
||
| Button(authService.string.cancelButtonLabel, action: state.cancel) | ||
| } | ||
| .padding(.horizontal) | ||
| } | ||
|
|
||
| Spacer() | ||
| } | ||
| .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top) | ||
| .navigationBarTitleDisplayMode(.inline) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
.foregroundStyleinstead of the deprecated.foregroundColormodifier. In modern SwiftUI (iOS 15+),.foregroundStyleis preferred for setting the color or style of views, and.foregroundStyle(.tint)is the idiomatic way to apply the accent color.