Skip to content

Commit e2797a3

Browse files
fix: allow custom callback for email link sign-in
1 parent 0b7037f commit e2797a3

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Services/AuthService.swift

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ public final class AuthService {
141141
private var listenerManager: AuthListenerManager?
142142

143143
var emailSignInEnabled = false
144+
private var emailSignInCallback: (@MainActor () -> Void)?
144145

145146
private var providers: [AuthProviderUI] = []
146147

@@ -151,12 +152,18 @@ public final class AuthService {
151152
public func renderButtons(spacing: CGFloat = 16) -> AnyView {
152153
AnyView(
153154
VStack(spacing: spacing) {
154-
AuthProviderButton(
155-
label: string.signInWithEmailLinkViewTitle,
156-
style: .email,
157-
accessibilityId: "sign-in-with-email-link-button"
158-
) {
159-
self.navigator.push(.emailLink)
155+
if emailSignInEnabled {
156+
AuthProviderButton(
157+
label: string.signInWithEmailLinkViewTitle,
158+
style: .email,
159+
accessibilityId: "sign-in-with-email-link-button"
160+
) {
161+
if let callback = self.emailSignInCallback {
162+
callback()
163+
} else {
164+
self.navigator.push(.emailLink)
165+
}
166+
}
160167
}
161168
ForEach(providers, id: \.id) { provider in
162169
provider.authButton()
@@ -309,8 +316,17 @@ public extension AuthService {
309316
// MARK: - Email/Password Sign In
310317

311318
public extension AuthService {
319+
/// Enable email sign-in with default behavior (navigates to email link view)
312320
func withEmailSignIn() -> AuthService {
321+
return withEmailSignIn { [weak self] in
322+
self?.navigator.push(.emailLink)
323+
}
324+
}
325+
326+
/// Enable email sign-in with custom callback
327+
func withEmailSignIn(onTap: @escaping @MainActor () -> Void) -> AuthService {
313328
emailSignInEnabled = true
329+
emailSignInCallback = onTap
314330
return self
315331
}
316332

0 commit comments

Comments
 (0)