You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Firebase Authentication SwiftUI:重置密码后邮箱验证状态意外变为true

Firebase Authentication重置密码后自动将isEmailVerified设为true是否为预期行为?

我在iOS应用中使用Firebase Authentication,已实现注册时的邮箱验证功能,登录时会检查邮箱是否验证,未验证的用户无法进入应用,这部分功能正常。但发现以下异常行为:

  • 用户注册邮箱和密码,但未验证邮箱;
  • 因邮箱未验证,无法进入应用;
  • 用户未验证邮箱就发起密码重置;
  • 重置密码完成后,用户可以进入应用,因为isEmailVerified变为了true。

我认为邮箱验证和密码重置是独立流程,isEmailVerified应该保持false,用户仍需验证邮箱才能进入应用。请问这是Firebase Authentication的预期行为吗?

相关代码

@MainActor
func signInWithEmail() async {
    isLoading = true
    
    validateEmail()
    validatePassword()
    
    if emailCredentials.email.isEmpty {
        emailValidationState.email = .invalid("Email is required")
        isLoading = false
        return
    }
    if emailCredentials.password.isEmpty {
        emailValidationState.password = .invalid("Password is required")
        isLoading = false
        return
    }
    
    guard case .valid = emailValidationState.email,
          case .valid = emailValidationState.password else {
        isLoading = false
        return
    }
    
    do {
        let result = try await authService.signInWithEmail(
            email: emailCredentials.email,
            password: emailCredentials.password
        )
        print("BBBB \(result.user.isEmailVerified)")
        if !result.user.isEmailVerified {
            emailVerificationState.credentials = AuthenticationModel.CreateAccountCredentials(
                email: emailCredentials.email,
                password: emailCredentials.password
            )
            emailVerificationState.email = emailCredentials.email
            try await result.user.sendEmailVerification()
            emailAuthAlert.message = AppConstants.Alert.Message.format(
                AppConstants.Alert.Message.emailVerificationSent,
                with: emailCredentials.email
            )
            emailAuthAlert.showAlert = true
            
        } else {
            handleSuccessfulAuthentication(for: .email)
        }
        
    } catch {
        handleAuthError(error, for: .emailAuth)
    }
    
    isLoading = false
}

@MainActor
func resetPassword() async {
    isLoading = true
    
    validateResetPasswordEmail()
    
    if resetPasswordCredentials.email.isEmpty {
        resetPasswordValidationState.email = .invalid("Email is required")
        isLoading = false
        return
    }
    
    guard case .valid = resetPasswordValidationState.email else {
        isLoading = false
        return
    }
    
    do {
        try await authService.resetPassword(email: resetPasswordCredentials.email)
        forgotPasswordAlert.message = AppConstants.Alert.Message.format(
            AppConstants.Alert.Message.passwordResetSent,
            with: resetPasswordCredentials.email
        )
        
        forgotPasswordAlert.showAlert = true
    } catch {
        handleAuthError(error, for: .forgotPassword)
    }
    
    isLoading = false
}

内容的提问来源于stack exchange,提问作者Tulon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 10:08:15