Repository navigation
feat(auth): add content slots to email sign-in screens #1414
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
Open
demolaf
wants to merge
7
commits into
auth/phone-content-slots
Choose a base branch
from
auth/email-content-slots
base: auth/phone-content-slots
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e622933
feat(auth): add content slots to email sign-in screens
demolaf 3e4ebdb
fix(auth): address review of the email content slots
demolaf 05d3f96
docs(auth): point email screen docs at the whole-screen pickerContent
demolaf 848764a
feat(auth): add a signUp route for a pushed email sign-up screen
demolaf 2065078
fix(auth): close the sign-up route after signing in and add SignUpView
demolaf 4ff8a8f
feat(auth): add a signIn route and goToEmailSignIn for a pushed email…
demolaf d5cfb5c
fix(auth): reset pushed email routes after sign-in, sign-out, dismiss…
demolaf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/DefaultEmailAuthContent.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| .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") | ||
| } | ||
| } | ||
73 changes: 73 additions & 0 deletions
73
FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/DefaultEmailLinkContent.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
|
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. |
||
| .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) | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The submit button is not disabled when
state.isLoadingis 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.