When performing sensitive operations (like deleting a user or updating a password), Firebase may require reauthentication. You must catch the specific AuthServiceError and use the provided context to trigger the appropriate reauthentication flow.
OAuth Providers (Google, Apple, etc.)
Catch .oauthReauthenticationRequired(context) and call authService.reauthenticate(context:).
Email/Password
Catch .emailReauthenticationRequired(context), prompt the user for their password, create an EmailAuthProvider.credential, and call authService.reauthenticate(with:).
Phone
Catch .phoneReauthenticationRequired(context), verify the phone number via authService.verifyPhoneNumber(phoneNumber:), and call authService.reauthenticate(with:) using the resulting credential.
Email Link
Catch .emailLinkReauthenticationRequired(context), call authService.sendEmailSignInLink(email:isReauth:), and use authService.handleSignInLink(url:) when the user returns to the app.
// Example: OAuth Reauthentication
do {
try await authService.deleteUser()
} catch let error as AuthServiceError {
if case .oauthReauthenticationRequired(let context) = error {
try await authService.reauthenticate(context: context)
try await authService.deleteUser() // Retry
}
}