Skip to content

Commit c6a2d3c

Browse files
fix: linkaccounts reauth
1 parent c1d54e1 commit c6a2d3c

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Services/AuthService.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,7 @@ public final class AuthService {
221221
throw AuthServiceError.noCurrentUser
222222
}
223223

224-
try await withReauthenticationIfNeeded(on: user) {
225-
try await user.link(with: credentials)
226-
}
224+
try await user.link(with: credentials)
227225
updateAuthenticationState()
228226
} catch {
229227
// Possible conflicts from user.link():

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/AccountConflictModifier.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ struct AccountConflictModifier: ViewModifier {
3535
@Environment(\.mfaHandler) private var mfaHandler
3636
@Environment(\.reportError) private var reportError
3737
@State private var pendingCredentialForLinking: AuthCredential?
38+
@State private var reauthCoordinator = ReauthenticationCoordinator()
3839

3940
func body(content: Content) -> some View {
4041
content
4142
.environment(\.accountConflictHandler, handleAccountConflict)
43+
.withReauthentication(coordinator: reauthCoordinator)
4244
.onChange(of: authService.authenticationState) { _, newState in
4345
// Auto-link pending credential after successful sign-in
4446
if newState == .authenticated {
@@ -82,7 +84,12 @@ struct AccountConflictModifier: ViewModifier {
8284

8385
Task {
8486
do {
85-
try await authService.linkAccounts(credentials: credential)
87+
try await withReauthenticationIfNeeded(
88+
authService: authService,
89+
coordinator: reauthCoordinator
90+
) {
91+
try await authService.linkAccounts(credentials: credential)
92+
}
8693
// Successfully linked, clear the pending credential
8794
pendingCredentialForLinking = nil
8895
} catch {

0 commit comments

Comments
 (0)