Firebase用户重新身份验证初始化错误 [英] Firebase User re-authentication initialising error
问题描述
当任何用户想要从应用程序更新其密码时,我想更新同一FCM用户的密码,为此,我尝试了以下官方文档中定义的代码.
When any user wants to update his/her password from app, i want to update that password of same FCM user and for that i have tried below code which define in official doc.
这是该屏幕截图
这是我的代码
func authenticateAndUpdateFCMUserPassword(strNewPassword: String) {
let user = Auth.auth().currentUser
var credential: AuthCredential
// Prompt the user to re-provide their sign-in credentials
user?.reauthenticate(with: credential) { error in
if let error = error {
// An error happened.
} else {
// User re-authenticated.
}
}
Auth.auth().currentUser?.updatePassword(to: strNewPassword) { (error) in
if error != nil {
print("Error occur while updating password")
}
else {
print("Password Updated Successfully")
}
}
}
但是在上面的代码中,我在user?.reauthenticate
行遇到下面的错误
But in above code i'm facing below error at user?.reauthenticate
line
无法将类型'(_)->()'的值转换为预期的参数类型 "AuthDataResultCallback?" (aka'Optional<(Optional, 可选)->()>')
Cannot convert value of type '(_) -> ()' to expected argument type 'AuthDataResultCallback?' (aka 'Optional<(Optional, Optional) -> ()>')
所以我用下面的代码将其重写
so i re write that by below code
user?.reauthenticate(with: credential, completion: { (dataResult, errorr) in
if errorr != nil {
// An error happened.
} else {
// User re-authenticated.
}
})
但是在上面的代码中,我正面临下面的错误
but in above code i'm facing below error
在初始化之前使用的变量凭据"
Variable 'credential' used before being initialized
凭据仅定义一次,在此之前从未使用过
credential is defined only once and never used before this
有人可以让我知道我在做什么错吗?
will anyone please let me know what i'm doing wrong?
推荐答案
当我如下设置凭据变量时,错误对我来说消失了:
When I set my credential variable as below, the error went away for me:
var credential: AuthCredential = EmailAuthProvider.credential(withEmail: email, password: password)
此答案对我有帮助: https://stackoverflow.com/a/52160137/9625899
这篇关于Firebase用户重新身份验证初始化错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!