更新了重新验证用户的方法

问题描述 投票:3回答:1

我一直在寻找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。

有没有人更新方法的例子?

swift firebase firebase-authentication
1个回答
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

这些凭证可能有所不同

EmailAuthCredential

FacebookAuthCredential

GithubAuthCredential

GoogleAuthCredential

PhoneAuthCredential

PlayGamesAuthCredential

TwitterAuthCredential

根据您的身份验证方法初始化变量,例如如果您选择了电子邮件,则可以使用

var credential: AuthCredential = EmailAuthProvider.credential(withEmail: "email", password: "pass")
© www.soinside.com 2019 - 2024. All rights reserved.