Skip to content

Commit c2f4335

Browse files
Merge pull request #1321 from firebase/email-link-chainable-method
2 parents 8d616fa + 2c4de6f commit c2f4335

File tree

8 files changed

+32089
-31951
lines changed

8 files changed

+32089
-31951
lines changed

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Services/AuthService.swift

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public final class AuthService {
129129

130130
private var currentMFAResolver: MultiFactorResolver?
131131
private var listenerManager: AuthListenerManager?
132-
private var emailSignInCallback: (() -> Void)?
132+
private var emailLinkSignInCallback: (() -> Void)?
133133
private var providers: [AuthProviderUI] = []
134134

135135
public let configuration: AuthConfiguration
@@ -139,7 +139,8 @@ public final class AuthService {
139139
public var currentUser: User?
140140
public var authenticationState: AuthenticationState = .unauthenticated
141141
public var authenticationFlow: AuthenticationFlow = .signIn
142-
public var emailSignInEnabled = false
142+
public var emailPasswordSignInEnabled = false
143+
public var emailLinkSignInEnabled = false
143144
public private(set) var navigator = Navigator()
144145

145146
public var authView: AuthView? {
@@ -153,13 +154,13 @@ public final class AuthService {
153154
public func renderButtons(spacing: CGFloat = 16) -> AnyView {
154155
AnyView(
155156
VStack(spacing: spacing) {
156-
if emailSignInEnabled {
157+
if emailLinkSignInEnabled {
157158
AuthProviderButton(
158159
label: string.signInWithEmailLinkViewTitle,
159160
style: .email,
160161
accessibilityId: "sign-in-with-email-link-button"
161162
) {
162-
if let callback = self.emailSignInCallback {
163+
if let callback = self.emailLinkSignInCallback {
163164
callback()
164165
} else {
165166
self.navigator.push(.emailLink)
@@ -345,17 +346,9 @@ public extension AuthService {
345346
// MARK: - Email/Password Sign In
346347

347348
public extension AuthService {
348-
/// Enable email sign-in with default behavior (navigates to email link view)
349+
/// Enable email/password sign-in (EmailAuthView is shown directly in AuthPickerView)
349350
func withEmailSignIn() -> AuthService {
350-
return withEmailSignIn { [weak self] in
351-
self?.navigator.push(.emailLink)
352-
}
353-
}
354-
355-
/// Enable email sign-in with custom callback
356-
func withEmailSignIn(onTap: @escaping () -> Void) -> AuthService {
357-
emailSignInEnabled = true
358-
emailSignInCallback = onTap
351+
emailPasswordSignInEnabled = true
359352
return self
360353
}
361354

@@ -392,6 +385,20 @@ public extension AuthService {
392385
// MARK: - Email Link Sign In
393386

394387
public extension AuthService {
388+
/// Enable email link sign-in with default behavior (navigates to email link view)
389+
func withEmailLinkSignIn() -> AuthService {
390+
return withEmailLinkSignIn { [weak self] in
391+
self?.navigator.push(.emailLink)
392+
}
393+
}
394+
395+
/// Enable email link sign-in with custom callback
396+
func withEmailLinkSignIn(onTap: @escaping () -> Void) -> AuthService {
397+
emailLinkSignInEnabled = true
398+
emailLinkSignInCallback = onTap
399+
return self
400+
}
401+
395402
/// Send email link for sign-in or reauthentication
396403
/// - Parameters:
397404
/// - email: Email address to send link to

0 commit comments

Comments
 (0)