更新了重新认证用户的方法 [英] Updated approach to Reauthenticate a user

查看:80
本文介绍了更新了重新认证用户的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在查看 Firebase文档,并找到了重新验证用户身份的方法,如下所示.

I've been looking in the Firebase Documentation and found the method to reauthenticate a user shown below.

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.
  }
}

虽然从编译器得到如下错误和警告:

I get an error and a warning though from the compiler as follows:

错误:

在初始化之前使用的变量凭据"

Variable 'credential' used before being initialized

警告:

'reauthenticate(with:completion :)'已过时:请使用 reauthenticateAndRetrieveDataWithCredential:completion:用于 Objective-C或 Swift的reauthenticateAndRetrieveData(WithCredential:completion :) 代替.

'reauthenticate(with:completion:)' is deprecated: Please use reauthenticateAndRetrieveDataWithCredential:completion: for Objective-C or reauthenticateAndRetrieveData(WithCredential:completion:) for Swift instead.

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

Has anyone an example of an updated method?

推荐答案

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

You are getting error because you haven't initialize credential You have to initialize AuthCredential first

这些凭据可能与

EmailAuthCredential

FacebookAuthCredential

GithubAuthCredential

GoogleAuthCredential

PhoneAuthCredential

PlayGamesAuthCredential

TwitterAuthCredential

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

Initiziale the variable according to your authentication method e.g. if you have chosen email you can use like

var credential: AuthCredential = EmailAuthProvider.credential(withEmail: "email", password: "pass")

这篇关于更新了重新认证用户的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆