Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public struct AuthPickerView<Content: View>: View {
/// account conflicts and errors are handled the same as the default buttons.
///
/// Your screen replaces the logo, email sign-in, terms and the large "Sign in" title (the close
/// button stays), so show your own heading, email entry (for example one built around
/// ``EmailAuthView``) and any legal text you need. To keep the stock screen and only lay out
/// the provider buttons, use ``DefaultAuthPickerContent/init(authMethodPicker:)``.
/// button stays), so show your own heading, email entry (for example ``EmailAuthScreen``) and
/// any legal text you need. To keep the stock screen and only lay out the provider buttons, use
/// ``DefaultAuthPickerContent/init(authMethodPicker:)``.
///
/// Example:
/// ```swift
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
// 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

private enum FocusableField: Hashable {
case email
case password
case confirmPassword
}

/// The stock content of ``EmailAuthScreen``.
@MainActor
public struct DefaultEmailAuthContent: View {
public init(state: EmailAuthContentState) {
self.state = state
}

@Environment(AuthService.self) private var authService
@FocusState private var focus: FocusableField?
private let state: EmailAuthContentState

public var body: some View {
VStack(spacing: 16) {
AuthTextField(
text: state.email,
label: authService.string.emailFieldLabel,
prompt: authService.string.emailInputLabel,
keyboardType: .emailAddress,
contentType: .emailAddress,
validations: [
FormValidators.email,
],
maintainsValidationMessage: state.flow == .signUp,
onSubmit: { _ in
self.focus = .password
},
leading: {
Image(systemName: "at")
}
)
.focused($focus, equals: .email)
.accessibilityIdentifier("email-field")
AuthTextField(
text: state.password,
label: authService.string.passwordFieldLabel,
prompt: authService.string.passwordInputLabel,
contentType: .password,
isSecureTextField: true,
validations: state.flow == .signUp ? [
FormValidators.atLeast6Characters
] : [],
maintainsValidationMessage: state.flow == .signUp,
onSubmit: { _ in
if state.flow == .signIn {
state.signIn()
} else {
focus = .confirmPassword
}
},
leading: {
Image(systemName: "lock")
}
)
.submitLabel(.go)
.focused($focus, equals: .password)
.accessibilityIdentifier("password-field")
if state.flow == .signIn {
Button(action: state.goToPasswordRecovery) {
Text(authService.string.passwordButtonLabel)
.authCustomFont(.body, weight: .medium)
.frame(maxWidth: .infinity, alignment: .trailing)
}
.accessibilityIdentifier("password-recovery-button")
}

if state.flow == .signUp {
AuthTextField(
text: state.confirmPassword,
label: authService.string.confirmPasswordFieldLabel,
prompt: authService.string.confirmPasswordInputLabel,
contentType: .password,
isSecureTextField: true,
validations: [
FormValidators.confirmPassword(password: state.password.wrappedValue),
],
maintainsValidationMessage: true,
onSubmit: { _ in
state.signUp()
},
leading: {
Image(systemName: "lock")
}
)
.submitLabel(.go)
.focused($focus, equals: .confirmPassword)
.accessibilityIdentifier("confirm-password-field")
}

Button {
if state.flow == .signIn {
state.signIn()
} else {
state.signUp()
}
} label: {
if !state.isLoading {
Text(
state.flow == .signIn
? authService.string.signInWithEmailButtonLabel
: authService.string.signUpWithEmailButtonLabel
)
.padding(.vertical, 8)
.frame(maxWidth: .infinity)
} else {
ProgressView()
.progressViewStyle(CircularProgressViewStyle(tint: .white))
.padding(.vertical, 8)
.frame(maxWidth: .infinity)
}
}
.disabled(!state.isValid)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The submit button is not disabled when state.isLoading is true. Although the screen's submit logic guards against multiple submissions, disabling the button during loading provides a better UX and prevents redundant tap interactions.

Suggested change
.disabled(!state.isValid)
.disabled(!state.isValid || state.isLoading)

.padding([.top, .bottom], 8)
.frame(maxWidth: .infinity)
.authCTAButtonStyle()
.accessibilityIdentifier("sign-in-button")
}
Button(action: state.switchFlow) {
HStack(spacing: 4) {
Text(
state.flow == .signIn
? authService.string.dontHaveAnAccountYetLabel
: authService.string.alreadyHaveAnAccountLabel
)
.authCustomFont(.body)
.foregroundStyle(Color(.label))
Text(
state.flow == .signUp
? authService.string.emailLoginFlowLabel
: authService.string.emailSignUpFlowLabel
)
.authCustomFont(.body, weight: .medium)
}
}
.accessibilityIdentifier("switch-auth-flow")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// 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 ``EmailLinkScreen``.
@MainActor
public struct DefaultEmailLinkContent: View {
public init(state: EmailLinkContentState) {
self.state = state
}

@Environment(AuthService.self) private var authService
private let state: EmailLinkContentState

public var body: some View {
VStack(spacing: 24) {
AuthTextField(
text: state.email,
label: authService.string.signInLinkEmailFieldLabel,
prompt: authService.string.emailInputLabel,
keyboardType: .emailAddress,
contentType: .emailAddress,
validations: [
FormValidators.email,
],
leading: {
Image(systemName: "at")
}
)
.accessibilityIdentifier("email-link-email-field")
Button(action: state.sendSignInLink) {
Text(authService.string.sendEmailLinkButtonLabel)
.padding(.vertical, 8)
.frame(maxWidth: .infinity)
}
.authCTAButtonStyle()
.disabled(!state.isValid)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The submit button is not disabled when state.isLoading is true. Disabling the button during loading provides a better UX and prevents redundant tap interactions.

Suggested change
.disabled(!state.isValid)
.disabled(!state.isValid || state.isLoading)

.padding([.top, .bottom], 8)
.frame(maxWidth: .infinity)
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
.navigationTitle(authService.string.signInWithEmailLinkViewTitle)
.safeAreaPadding()
.alert(
authService.string.signInWithEmailLinkViewTitle,
isPresented: Binding(
get: { state.didSend },
set: { isPresented in
if !isPresented {
state.dismissAlert()
}
}
)
) {
Button(authService.string.okButtonLabel) {}
} message: {
Text(authService.string.signInWithEmailLinkViewMessage)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// 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 ``PasswordRecoveryScreen``.
@MainActor
public struct DefaultPasswordRecoveryContent: View {
public init(state: PasswordRecoveryContentState) {
self.state = state
}

@Environment(AuthService.self) private var authService
private let state: PasswordRecoveryContentState

public var body: some View {
VStack(spacing: 24) {
AuthTextField(
text: state.email,
label: authService.string.passwordRecoveryEmailFieldLabel,
prompt: authService.string.emailInputLabel,
keyboardType: .emailAddress,
contentType: .emailAddress,
validations: [
FormValidators.email,
],
leading: {
Image(systemName: "at")
}
)
Button(action: state.sendResetLink) {
Text(authService.string.forgotPasswordInputLabel)
.padding(.vertical, 8)
.frame(maxWidth: .infinity)
}
.disabled(!state.isValid)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The submit button is not disabled when state.isLoading is true. Disabling the button during loading provides a better UX and prevents redundant tap interactions.

Suggested change
.disabled(!state.isValid)
.disabled(!state.isValid || state.isLoading)

.frame(maxWidth: .infinity)
.authCTAButtonStyle()
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
.navigationTitle(authService.string.passwordRecoveryTitle)
.safeAreaPadding()
.sheet(isPresented: Binding(
get: { state.didSend },
set: { isPresented in
if !isPresented {
state.hideSuccess()
}
}
)) {
successSheet
}
}

@ViewBuilder
@MainActor
private var successSheet: some View {
VStack {
Text(authService.string.passwordRecoveryEmailSentTitle)
.authFont(.largeTitle)
.fontWeight(.bold)
.padding()
Text(authService.string.passwordRecoveryHelperMessage)
.authCustomFont(.body)
.padding()

Divider()

Text(String(format: authService.string.passwordRecoveryEmailSentMessage, state.sentEmail))
.authCustomFont(.body)
.padding()

Divider()

Button(authService.string.okButtonLabel, action: state.dismissSuccess)
.padding()
}
.padding()
}
}
Loading