重新验证用户使用Firebase / Xcode的错误(用于更新用户电子邮件)

时间:2019-06-21 14:17:45

标签: swift xcode firebase firebase-authentication

我正在尝试使用Xcode版本10.2.1和Firebase为iOS应用创建“更新电子邮件”屏幕。使用Firebase更新电子邮件的所有代码都可以正常工作,但是当我尝试重新验证用户身份时出现以下错误:

  

无法将类型'(_)->()'的值转换为预期的参数类型'AuthDataResultCallback? (aka'可选<(可选,可选)->()>')

哦,我正在使用电子邮件凭据来验证用户。

我在这里搜索了多个线程,并通过Firebase文档进行了搜索,似乎无法弄清楚是什么原因导致了此错误。

这是我的代码,是我从Firebase Documentation以及this thread提取的:

let user = Auth.auth().currentUser
var credential: AuthCredential = EmailAuthProvider.credential(withEmail: "email", password: "pass")

user?.reauthenticate(with: credential) { error in
     if let error = error {
        // error handled here
     } else {
        // success
     }
}

错误显示在“ user?.reauthenticate(with:credential){错误的行中。

任何人都不知道是什么原因造成的吗?

(而且,如果我缺少明显的内容,我们深表歉意。我对使用Swift / Xcode相对较新。)

谢谢!

1 个答案:

答案 0 :(得分:0)

我认为您缺少 result 参数

let user = Auth.auth().currentUser
var credential: AuthCredential = EmailAuthProvider.credential(withEmail: "email", password: "pass")

user?.reauthenticate(with: credential) { result, error in
     if let error = error {
        // error handled here
     } else {
        // success
     }
}

其中的结果是AuthDataResult,其中包含成功登录的结果。