我一直在寻找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或 Swift的reauthenticateAndRetrieveData(WithCredential:completion :) 代替。
有人有更新方法的例子吗?
答案 0 :(得分:5)
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")