我一直在寻找Firebase Documentation,并找到了重新验证下面显示的用户的方法。
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.
}
}
我从编译器收到错误和警告,如下所示:
错误:
在初始化之前使用变量'凭证'
警告:
'reauthenticate(with:completion :)'已弃用:请使用reauthenticateAndRetrieveDataWithCredential:completion:对于Objective-C或reauthenticateAndRetrieveData(WithCredential:completion :)来代替Swift。
有没有人更新方法的例子?
let user = Auth.auth().currentUser
var credential: AuthCredential
user?.reauthenticateAndRetrieveData(with: credential, completion: {(authResult, error) in
if let error = error {
// An error happened.
}else{
// User re-authenticated.
}
})
您收到错误是因为您尚未初始化凭据您必须首先初始化AuthCredential
这些凭证可能有所不同
根据您的身份验证方法初始化变量,例如如果您选择了电子邮件,则可以使用
var credential: AuthCredential = EmailAuthProvider.credential(withEmail: "email", password: "pass")