如何注销和删除用户通过FirebaseUI Swift 5注册 [英] How to Sign out and Delete Users Register By FirebaseUI Swift 5

查看:79
本文介绍了如何注销和删除用户通过FirebaseUI Swift 5注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让我的应用能够注销/删除用户以及键入此代码时

I want to give my app the ability to Log out/delete the user and when I type this code

    @IBAction func deleteTheAccountButtonHasBeenTapped(_ sender: Any) {
    
    let user = Auth.auth().currentUser
    var credential: AuthCredential
    
    user?.reauthenticateAndRetrieveData(with: credential, completion: {(authResult, error) in
        if let error = error {
            // An error happened.
            print(error)
        }else{
            //user re-authenticated
            user?.delete { error in
              if let error = error {
                // An error happened.
                print(error)
              } else {
                // Account deleted.
                let vc = UIStoryboard.init(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "LoginVC") as! LoginVC
                self.present(vc, animated:true, completion:nil)
              }
            }
            
        }
    })
}

我收到此错误:

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

Variable 'credential' used before being initialized

有人可以帮助我吗?

推荐答案

错误消息非常明显:初始化之前,您正在使用credential.

The error message is pretty explicit: you're using credential before you initialized it.

要删除用户,您需要先重新验证用户身份,如

In order to delete the user, you need to first reauthenticate them, as shown in the documentation on reauthenticating the user. Your version doesn't implement this comment from that code:

// Prompt the user to re-provide their sign-in credentials

如何重新验证用户取决于提供者.例如,对于电子邮件/密码,您将获得:

How to reauthenticate the user depends on the provider. For example for email/password, you'd get them with:

credential = EmailAuthProvider.credential(withEmail: email, password: password)

查看全文

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